You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incorrect file/line blamed for errors caused by new SomeClass #7771
Fatal error: Uncaught Error: Class "IDontExist" not found in C:\stable\test4.php:5
But I expected this output instead:
Fatal error: Uncaught Error: Class "IDontExist" not found in C:\stable\SomeClass.php:4
This frequently causes issues with my telemetry because incorrect subsystems are getting blamed for errors when third-party plugin code comes into play.
Note that this is not a fatal error and thus can be caught. https://3v4l.org/ghG5d#v8.1.0 Not sure what the full stack trace should be if this were to be changed to the position of the constant itself. Just one more frame with the constant AST itself?
The approach in the PR is to simply replace filename/lineno in the exception, similar to ErrorException. Since there are tons paths for throwing errors in constant expressions I avoided passing the name/lineno by storing it in the execution globals.
Unfortunately the lineno in the AST somewhere. I'm still trying to figure out why. Let me know if this approach is ok before I spend too much time on this.
Activity
nikic commentedon Dec 13, 2021
Reporting the line of the AST evaluation would indeed be preferable, and I believe the necessary information is already present, but not used.
iluuu1994 commentedon Dec 13, 2021
Note that this is not a fatal error and thus can be caught. https://3v4l.org/ghG5d#v8.1.0 Not sure what the full stack trace should be if this were to be changed to the position of the constant itself. Just one more frame with the constant AST itself?
cmb69 commentedon Dec 14, 2021
See also https://bugs.php.net/bug.php?id=47405.
iluuu1994 commentedon Feb 5, 2022
I created a small POC here. https://github.com/php/php-src/compare/master...iluuu1994:gh-7771?expand=1
The approach in the PR is to simply replace filename/lineno in the exception, similar to
ErrorException. Since there are tons paths for throwing errors in constant expressions I avoided passing the name/lineno by storing it in the execution globals.Unfortunately the lineno in the AST somewhere. I'm still trying to figure out why. Let me know if this approach is ok before I spend too much time on this.