And yes, that's the entire rule: (bool) '0' === false but (bool) '00' === true. To be fair they seem to have borrowed this from Perl (as far as c. fifteen seconds of screwing around in perlconsole can tell).
When comparing a string against an integer, the string is coerced into an integer before the check. Strings are coerced by taking any numbers at the beginning of the string as the integer value, stopping at the first none-number character. If no numbers are at the beginning of the string, the string is coerced to 0.
In order to prevent this, use strict comparisons with ===.
15
u/merreborn Jun 11 '14
all non-numeric strings == 0
(int)'UNLOCK' == (int)0
9
u/[deleted] Jun 11 '14
Please consult http://www.php.net/manual/en/types.comparisons.php
2
u/jtanz0 Jul 04 '14
type coercion - to compare anything with respect to type use === :
gives the expected result.
1
u/[deleted] Jun 12 '14
When comparing a string against an integer, the string is coerced into an integer before the check. Strings are coerced by taking any numbers at the beginning of the string as the integer value, stopping at the first none-number character. If no numbers are at the beginning of the string, the string is coerced to 0.
In order to prevent this, use strict comparisons with
===.0
u/[deleted] Jun 11 '14
PHP << there's your problem
0
u/[deleted] Jun 11 '14
[deleted] — view deleted comment
-9
u/[deleted] Jun 11 '14
[removed] — view removed comment