Allow catching as ParseError "Non-abstract method C::foo() must contain a body"
Open
Nobody has claimed this yet.
Feature
Status: Needs Triage
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the eval() path in the PHP interpreter and compare how the shown syntax error becomes a ParseError with how the non-abstract method check currently terminates execution. Use the issue's two eval() examples as the reproducer; done means the second case can be caught as ParseError and execution continues.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100