Skip to content

Bug5512#5513

Merged
rlerdorf merged 2 commits intov6from
bug5512
Mar 29, 2026
Merged

Bug5512#5513
rlerdorf merged 2 commits intov6from
bug5512

Conversation

@rlerdorf
Copy link
Copy Markdown
Member

When a set hook has no explicit params node in the AST, the implicit $value variable is now added to scope with the property's declared type. This is done by looking up the property via the PropertyScope FQSEN already available in the context.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes analysis of PHP 8.4 property set hooks where the AST omits an explicit params node by injecting the implicit $value variable into the hook scope, typed as the declaring property’s union type (looked up via the PropertyScope FQSEN). This prevents false PhanUndeclaredVariable warnings and better matches PHP 8.4 semantics.

Changes:

  • Add implicit $value to set hook scope when no params node exists, using the property’s declared type from the codebase.
  • Add a PHP 8.4 regression test covering implicit $value usage in hooks.
  • Add an expected-output fixture asserting only the intended type-mismatch warning remains.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/Phan/BlockAnalysisVisitor.php Injects implicit $value into set hook scope when params are missing, with type derived from the property in PropertyScope.
tests/php84_files/src/5512_implicit_value_property_hook.php New regression test cases for implicit $value in set hooks.
tests/php84_files/expected/5512_implicit_value_property_hook.php.expected Expected output updated to assert only the type-mismatch warning is emitted.

@rlerdorf rlerdorf merged commit 062c394 into v6 Mar 29, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants