php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75252 Incorrect token formatting on two parse errors in one request
Submitted: 2017-09-24 06:46 UTC Modified: 2017-09-24 06:57 UTC
From: nikic@php.net Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 7.0.23 OS:
Private report: No CVE-ID: None
 [2017-09-24 06:46 UTC] nikic@php.net
Description:
------------
If two ParseErrors are thrown in the same request (e.g. by using eval or the ast extension), the replacement of the token name with the token value is only performed for the first error.

This happens because the CG(parse_error) global does not get reset if the ParseError exception is caught.

Test script:
---------------
<?php

$code = <<<'CODE'
function test_missing_semicolon() : string {
     $x = []
     FOO
}
CODE;

try {
    eval($code);
} catch (ParseError $e) {
    var_dump($e->getMessage());
}

try {
    eval($code);
} catch (ParseError $e) {
    var_dump($e->getMessage());
}

Expected result:
----------------
string(41) "syntax error, unexpected 'FOO' (T_STRING)"
string(41) "syntax error, unexpected 'FOO' (T_STRING)"

Actual result:
--------------
string(41) "syntax error, unexpected 'FOO' (T_STRING)"
string(46) "syntax error, unexpected identifier (T_STRING)"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-09-24 06:56 UTC] nikic@php.net
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=73d6456d7d6be62340b3607805a45cbf420c1cb8
Log: Fixed bug #75252
 [2017-09-24 06:56 UTC] nikic@php.net
-Status: Open +Status: Closed
 [2017-09-24 06:57 UTC] nikic@php.net
-Assigned To: +Assigned To: nikic
 [2017-09-24 06:57 UTC] nikic@php.net
This issue has been originally reported by Tyson Andre at https://github.com/nikic/php-ast/issues/79.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Oct 15 04:01:26 2024 UTC