[ciapug] yeah, weakly typed languages
Barry Von Ahsen
barry at vonahsen.com
Wed Apr 4 11:15:33 CDT 2007
echo "phpversion: ".phpversion()."<br>";
$a = "01234";
$b = "1234";
echo "a:". $a."<br>";
echo "b:". $b."<br>";
if($a == $b) { echo "a==b"; } else { echo "a!=b"; } echo "<br>";
if($a === $b) { echo "a===b"; } else { echo "a!==b"; } echo "<br>";
echo "gettype(a):". gettype($a)."<br>";
echo "gettype(b):". gettype($b)."<br>";
$c = "0foo";
$d = "foo";
echo "c:". $c."<br>";
echo "d:". $d."<br>";
if($c == $d) { echo "c==d"; } else { echo "c!=d"; } echo "<br>";
if($c === $d) { echo "c===d"; } else { echo "c!==d"; } echo "<br>";
output:
phpversion: 4.4.0
a:01234
b:1234
a==b
a!==b
gettype(a):string
gettype(b):string
c:0foo
d:foo
c!=d
c!==d
I totally understand why "01234"==1234, but not why "01234"=="1234". If
I'm doing string=>string, no conversion should happen. However, if it
does, why doesn't "0foo"=>0 and "foo"=>0 so "0foo"=="foo" also?!?
-barry
More information about the ciapug
mailing list