var_dump(0123 == 123);
var_dump('0123' == 123);
var_dump('0123' === 123);

At first glance one might think that the leading zero on line one is simply of no value. But one would be wrong… In PHP, a leading zero in a number means that it’s an octal number.

Line one above will compare octal 123, which when converted to decimal is 83, and is not equal to 123 so the output will be false.

Line two has that octal number as a string, so we have to know how strings get converted to numbers. It will be coerced to an integer, and the leading zero will be ignored. Thus it will output true.

Line three will output false because the === operator will prevent coercion, and a string can not be identical to a number.

Watch out for that Octal!