php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61293 assigning 09 to variable
Submitted: 2012-03-05 18:24 UTC Modified: 2012-03-05 18:53 UTC
From: donmillhofer at yahoo dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: 5.3.10 OS: Windows Vista
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: donmillhofer at yahoo dot com
New email:
PHP Version: OS:

 

 [2012-03-05 18:24 UTC] donmillhofer at yahoo dot com
Description:
------------
My concern is that PHP treats the handling of variable assignment inconsistently.  For example if I assign 01 to a variable $i01 the result will be an int 1, the same as if I had assigned 1 to the variable.  This works for values of 01,02,03,04,05,06, and 07.  However 08 and 09 are assigned as 0!

See repeatable test below.



Test script:
---------------
Assign variables:
	$s09 = '09';
	$c09 = (integer) '09';
           $i09 = 09;

Result of var_dump($s09.' / '.$c09.' / '.$i09);
    	string '09 / 9 / 0'

Assign variables:
	$s07 = '07';
	$c07 = (integer) '07';
           $i07 = 07;

Result of var_dump($s07.' / '.$c07.' / '.$i07);
    	string '07 / 7 / 7'

And when I just dump the $iXX variable I get:

	var_dump($i09);
Result	int 0

	var_dump($i07);
Result	int 7

This looks like a bug to me. 


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-03-05 18:53 UTC] rasmus@php.net
-Status: Open +Status: Not a bug
 [2012-03-05 18:53 UTC] rasmus@php.net
Yes, you have discovered octal notation.

http://www.php.net/manual/en/language.types.integer.php
 [2012-03-05 23:58 UTC] anon at anon dot anon
It's been a bug for 10+ years. To this day nobody at PHP is smart enough to turn it into a syntax error condition, like it would be in a good or semi-good language.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Feb 05 04:01:31 2025 UTC