php.net |  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
 [2012-12-06 06:08 UTC] iam4webwork at hotmail dot com
Description:
------------
PHP fails to display error messages consistently when user provides invalid 
octals.

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 ...


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-12-06 06:12 UTC] rasmus@php.net
Octals are by definition identified by a single leading 0, not 2.
 [2012-12-06 06:12 UTC] rasmus@php.net
-Status: Open +Status: Not a bug
 [2012-12-06 07:53 UTC] nikic@php.net
@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: Fri Apr 19 22:01:28 2024 UTC