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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Tue May 28 17:01:31 2024 UTC