NYCPHP Meetup

NYPHP.org

[nycphp-talk] Why do "cool kids" choose PHP to build websites instead of Java

Gary Mort bz-gmort at beezifies.com
Thu Jan 3 05:14:10 EST 2008


Elliotte Rusty Harold wrote:
> % cat equality.php
> <?php
>
> $a = 0;
> $b = "eggs";
> $c = "spam";
>
> print ($a == $b) ? "a == b\n" : "a != b\n";
> print ($b == $c) ? "b == c\n" : "b != c\n";
> print ($a == $c) ? "a == c\n" : "a != c\n";
> print ($a == $d) ? "a == d\n" : "a != d\n";
> print ($b == $d) ? "b == d\n" : "b != d\n";
> print ($c == $d) ? "c == d\n" : "c != d\n";
> ?>
>
I don't see this as a problem, basically the issue being raised is:
PHP does not have strong typing, this 0, NULL, and false are all 
equivalent(add a $d=false; to the definitions and everything still comes 
out with the same result).

However, knowing that these 3 values are considered the same, you can 
replace 2 equal signs with 3, ===, and get the output your expecting.



More information about the talk mailing list