[ciapug] yeah, weakly typed languages
carl-olsen at mchsi.com
carl-olsen at mchsi.com
Wed Apr 4 11:44:23 CDT 2007
It's taking a while for this to sink in. The difference between the strings is that one is all numeric characters and the other is mixed. Don't ask me why this makes a difference. I'm just pointing it out and accepting that it explains the difference.
-------------- Original message ----------------------
From: Barry Von Ahsen <barry at vonahsen.com>
> 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
>
>
> _______________________________________________
> ciapug mailing list
> ciapug at cialug.org
> http://cialug.org/mailman/listinfo/ciapug
More information about the ciapug
mailing list