Conversation
Contributor
There was a problem hiding this comment.
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
$valuetosethook scope when noparamsnode exists, using the property’s declared type from the codebase. - Add a PHP 8.4 regression test covering implicit
$valueusage 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.