php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #75218 Change remaining uncatchable fatal errors for parsing into ParseError
Submitted: 2017-09-18 02:41 UTC Modified: 2017-09-24 13:49 UTC
From: tandre at themeetgroup dot com Assigned:
Status: Closed Package: Unknown/Other Function
PHP Version: 7.2.0RC2 OS:
Private report: No CVE-ID: None
 [2017-09-18 02:41 UTC] tandre at themeetgroup dot com
Description:
------------
Observed behavior: Evaluating, requiring, or even building the syntax tree of certain code snippets results in an uncatchable fatal error (Even if the code wouldn't be executed)
Expected behavior: Instead of an uncatchable fatal error, a ParseError (or other Error type, or a new Error subclass) should be thrown.

Affected PHP versions: PHP 7.0+, including 7.2.0RC2.
Requested fix version: PHP 7.2 (to avoid backwards compatibility breaks)


This also affects extensions using the C API to build an abstract syntax tree. See https://github.com/nikic/php-ast/issues/78

4 types of fatal errors are mentioned in the test script.

Test script:
---------------
function try_eval($code) {
    try {
        eval($code);
    } catch (\Throwable $e) {
        print("Caught throwable\n"); echo $e;
    }
}

// Would output: Fatal error: Multiple final modifiers are not allowed in /path/to/snippet.php(3) : eval()'d code on line 1 (Not catchable)
try_eval('if (false) {class C { final final function foo($fff) {}}}');
// Would output: Fatal error: Multiple access type modifiers are not allowed in /path/to/snippet.php(5) : eval()'d code on line 1 (not catchable)
try_eval('if (false) {class C { private protected $x; }}');
// Would output: Fatal error: __HALT_COMPILER() can only be used from the outermost scope in /path/to/snippet.php(5) : eval()'d code on line 1
try_eval('if (true) { __HALT_COMPILER(); }');
// Would output: Fatal error: Encoding must be a literal in /path/to/snippet.php(4) : eval()'d code on line 1 (Not catchable)
try_eval('declare(encoding=[]);');

Expected result:
----------------
The test script should print "Caught throwable" (and the exception) and proceed to subsequent statements

Actual result:
--------------
Only one line of output is emitted. The error can't be caught by set_error_handler() or any other means:

Fatal error: Multiple final modifiers are not allowed in /path/to/snippet.php(3) : eval()'d code on line 1

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-09-24 13:49 UTC] nikic@php.net
PR up at https://github.com/php/php-src/pull/2767, using a new CompileError exception type for these.
 [2018-06-16 10:41 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=d04917c7b361fd07e098fe29ae931fb6fac1d9e0
Log: Fixed bug #75218
 [2018-06-16 10:41 UTC] nikic@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 04:01:29 2024 UTC