[php-src] Issue #9333: Allow catching as ParseError "Non-abstract method C::foo() must contain a body"

From: Date: Sun, 14 Aug 2022 11:58:37 +0000
Subject: [php-src] Issue #9333: Allow catching as ParseError "Non-abstract method C::foo() must contain a body"
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-242217@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/9333 Author: thg2k ### Description Since PHP 7 it is possible to catch syntax errors in PHP files during inclusion, which is a very nice feature, such as: ```php try { eval("class C { function foo() }"); } catch (\Throwable $e) { print "CAUGHT [" . get_class($e) . "]: " . $e->getMessage() . "\n"; } // prints: CAUGHT [ParseError]: syntax error, unexpected token "}", expecting ";" or "{" // execution continues ``` Unfortunately, the same is not possible in case the error is a non-abstract method without body: ```php try { eval("class C { function foo(); }"); } catch (\Throwable $e) { print "CAUGHT [" . get_class($e) . "]: " . $e->getMessage() . "\n"; } // prints: Fatal error: Non-abstract method C::foo() must contain body in /in/YY0Wu(13) : eval()'d code on line 1 // execution terminates ``` Would it be possible to implement a throw also for this case? https://3v4l.org/YY0Wu

« previous php.bugs (#242217) next »