Jeremy's Blog

Re: Octopussy numbers in PHP

by Jeremy on Feb.01, 2008, under Uncategorized

John Lim made a post about a problem he had with certain output that he believed should be the same. He requires registration for comments, and I couldn’t be bothered, so here’s my response.

Check out the integer literals example in the PHP Manual for the answer to why he’s having issues. His sample code is:

echo 09," => (09) <br>";
echo 9," => (9) <br>";

The reason that doesn’t work as expected is because 09 when used as an integer is interpreted as an octal number. So, the result that he’s seeing is:

0 => (09)
9 => (9)

That’s just how integer literals work and it’s documented behavior. It’s not a bug. Well, it’s a bug in his code, but it’s not a bug in PHP.

:

Comments are closed.

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!