|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63705 lack of error message
Submitted: 2012-12-06 06:08 UTC Modified: 2012-12-06 06:12 UTC
From: iam4webwork at hotmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: Irrelevant OS:
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.
Block user comment
Status: Assign to:
Bug Type:
From: iam4webwork at hotmail dot com
New email:
PHP Version: OS:


 [2012-12-06 06:08 UTC] iam4webwork at hotmail dot com
PHP fails to display error messages consistently when user provides invalid 

Test script:
$octal          = 00812;
$another        = 00934;
var_dump( $octal, $another); 

$will_error   =  01c;
var_dump( $will_error );

The first two octals PHP accepts as valid input, and silently truncates each. It only displays an error message for 01c and mentions the 'c' being a problem.  Why doesn't PHP consistently reject invalid octal values and display error messages?

Expected result:
I expected error messages to result for each of the first two invalid octals.  
Instead PHP blindly accepted them while having each evaluate as zero.  It only 
caught on to 01c being a bad octal value.

Actual result:
int 0

int 0

Parse error: syntax error, unexpected 'c' (T_STRING) in ...


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-12-06 06:12 UTC]
Octals are by definition identified by a single leading 0, not 2.
 [2012-12-06 06:12 UTC]
-Status: Open +Status: Not a bug
 [2012-12-06 07:53 UTC]
@rasmus: I still think that we should throw a notice/warning (in the lexer?) when an invalid octal is provided. Or do we have odd BC reasons preventing us from doing so?
 [2012-12-06 23:16 UTC] iam4webwork at hotmail dot com
I respectfully disagree with the Father of PHP about octals only being octals if 
they have precisely one and only one leading zero.  Here is my proof:

$a = 012;
$b = 0012;
$c = 00012;
var_dump($a,$b,$c); // all are int 10 in PHP5.4 

If $b and $c were not octals then one might expect them to evaluate as 12 or be 
rejected as invalid data.  

The failure to provide error messages with respect to poorly formed octals is 
indeed a bug and can lead to weird comparisons like this:

0777 == 0777812 // true
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Feb 25 10:01:26 2024 UTC