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: [email protected] 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] [email protected]
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] [email protected]
-Status: Open +Status: Closed
 [2017-09-24 06:57 UTC] [email protected]
-Assigned To: +Assigned To: nikic
 [2017-09-24 06:57 UTC] [email protected]
This issue has been originally reported by Tyson Andre at https://github.com/nikic/php-ast/issues/79.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jun 09 19:01:26 2025 UTC