Skip to content

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

@thg2k

Description

@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:

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:

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions