php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71806 php_strip_whitespace() fails on some numerical values
Submitted: 2016-03-11 21:25 UTC Modified: 2016-03-12 09:59 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: gregzem at inbox dot ru Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 7.0.4 OS: ANY
Private report: No CVE-ID: None
 [2016-03-11 21:25 UTC] gregzem at inbox dot ru
Description:
------------
If the source contains digits starting with 0, php_strip_whitespace() fails to process the source and produces the parser error.

<?php
    echo 0987654321; 
?>

This source will generate the following error:

PHP Parse error:  Invalid numeric literal in testfile.php on line 2



Test script:
---------------
testfile.php

<?php
    echo 0987654321; 
?>



test.php:

<?php
  $test = php_strip_whitespace('testfile.php');
?>


Expected result:
----------------
php_strip_whitespace processes the file without any errors.

Actual result:
--------------
php_strip_whitespace generates PHP Parse error:  Invalid numeric literal in testfile.php on line 2

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-03-11 21:46 UTC] nikic@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=02743f43c2de313e30320f2fb2d995937ce9881b
Log: Fixed bug #71806
 [2016-03-11 21:46 UTC] nikic@php.net
-Status: Open +Status: Closed
 [2016-03-12 05:13 UTC] requinix@php.net
-Assigned To: +Assigned To: requinix
 [2016-03-12 05:13 UTC] requinix@php.net
To be clear, 0987654321 *isn't* a valid number: the leading 0 indicates octal and '9' and '8' are not allowed in octal. Trying to execute testfile.php (in PHP 7) will produce the parse error.

http://php.net/manual/en/language.types.integer.php#language.types.integer.syntax
> Warning
> Prior to PHP 7, if an invalid digit was given in an octal integer (i.e. 8 or
> 9), the rest of the number was ignored. Since PHP 7, a parse error is emitted.

@nikic's fix only *suppresses* the error when running that code through php_strip_whitespace().
 [2016-03-12 05:13 UTC] requinix@php.net
-Assigned To: requinix +Assigned To: nikic
 [2016-03-12 09:59 UTC] nikic@php.net
To clarify, the reason why I'm suppressing the error is that our "lexy" functions are supposed to be robust and able to process code that may not be valid in the current version of PHP or may only be an excerpt of valid code. token_get_all() and the highlight_string()/highlight_file() functions already suppress lexer errors, so now php_strip_whitespace() does as well.
 [2016-07-20 11:33 UTC] davey@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=02743f43c2de313e30320f2fb2d995937ce9881b
Log: Fixed bug #71806
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 10:01:29 2024 UTC