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
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: nikic@php.net
New email:
PHP Version: OS:

 

 [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

Add a Patch

Pull Requests

Add a Pull Request

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: Thu Apr 25 23:01:29 2024 UTC