Req #75218 [Opn->Csd]: Change remaining uncatchable fatal errors for parsing into ParseError
| From: | nikic@php.net | Date: | Sat, 16 Jun 2018 10:41:21 +0000 |
| Subject: | Req #75218 [Opn->Csd]: Change remaining uncatchable fatal errors for parsing into ParseError | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-215752@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75218&edit=1
ID: 75218
Updated by: nikic@php.net
Reported by: tandre at themeetgroup dot com
Summary: Change remaining uncatchable fatal errors for
parsing into ParseError
-Status: Open
+Status: Closed
Type: Feature/Change Request
Package: Unknown/Other Function
PHP Version: 7.2.0RC2
Block user comment: N
Private report: N
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[2017-09-24 13:49:04] nikic@php.net
PR up at https://github.com/php/php-src/pull/2767, using
a new CompileError exception type for these.
------------------------------------------------------------------------
[2017-09-18 02:41:39] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75218&edit=1