How PHP is getting this result?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
BornForCode
Forum Contributor
Posts: 147
Joined: Mon Feb 11, 2008 1:56 am

How PHP is getting this result?

Post by BornForCode »

Hello a test scenario fro ZCE:

Code: Select all

 
$y = 08;
$y += 15;
echo $y;
 
Running this code gives 15, when i was expecting 23, why this happens?
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Re: How PHP is getting this result?

Post by Mordred »

Numbers starting with 0 are octal.

8 = 8
08 = 0
10 = 10
010 = 8
Post Reply