Interview question: In php, is 123==0123?

This code:


will get you:

int 123
int 83

This is because 0123 is octal notation (because of the 0 at the beginning), while 123 is decimal.

For more information, you can take a look at the Integer section of the manual.

An even trickier question would have been to ask about 79 and 079, for instance :


will get you :

int 79
int 7

(9 is not a valid digit in octal 😉 )

Leave a Comment