Re:Why 1 && 2 == 2
by jcampbell1 on Thursday July 18, 2013 @11:22PM
(#6068138)
Thank god he didn't try php.
In php ?: is javascript's || Unfortunately there is no && that works correctly.
[ Parent
| on HN ]
Re:Why 1 && 2 == 2
by mattparlane on Thursday July 18, 2013 @11:32PM
(#6068166)
Came here to say this. If you use var_dump you can see it's coercing the result to a bool.
$ php -r 'var_dump(1 && 2);'
bool(true)Exactly, it's not that bizarre. PHP assumes when you're using && you're going to have a boolean outcome.
The odd bit is that casting a boolean to a string[0] with echo coerces the result to (string) "1" for true and (string) "" for false.
[0]: http://www.php.net/manual/en/language.types.string.php#langu...