Skip to content

Fix GH-18105: Wrong file & line on exception trace with trait default parameter#21657

Open
iliaal wants to merge 1 commit intophp:masterfrom
iliaal:fix/gh-18105-wrong-exception-file-in-trait
Open

Fix GH-18105: Wrong file & line on exception trace with trait default parameter#21657
iliaal wants to merge 1 commit intophp:masterfrom
iliaal:fix/gh-18105-wrong-exception-file-in-trait

Conversation

@iliaal
Copy link
Copy Markdown
Contributor

@iliaal iliaal commented Apr 6, 2026

When a trait method has a default parameter using new (e.g., new ThrowableParam) and the constructor throws, the exception reports the file of the class using the trait, not the file where the throw occurs.

zend_ast_evaluate_ex sets EG(filename_override) to the scope's filename during constant expression evaluation. For trait clones, the scope points to the using class's file. When ZEND_AST_NEW calls the constructor and it throws, zend_default_exception_new picks up this stale override.

Save and clear EG(filename_override) before constructor calls in zend_ast_evaluate_inner's ZEND_AST_NEW handler, restore after. The VM's normal stack frame resolution then applies during constructor execution.

Fixes #18105

…ult parameter

When a trait method has a default parameter using `new` and the constructor
throws, the exception's file/line pointed to the class using the trait rather
than where the throw actually occurred. `EG(filename_override)`, set to the
scope's filename during AST evaluation, leaked into the constructor's VM
re-entry.

Clear the override before constructor calls in `zend_ast_evaluate_inner`'s
ZEND_AST_NEW handler so normal stack frame resolution applies.

Closes phpGH-18105
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong line & file on error trace

2 participants