Repository navigation
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #902 +/- ##
=========================================
Coverage 99.71% 99.71%
- Complexity 1970 1973 +3
=========================================
Files 147 147
Lines 4488 4490 +2
=========================================
+ Hits 4475 4477 +2
Misses 13 13 ☔ View full report in Codecov by Harness. |
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.
Problem
Code in a class body outside its methods sees variables from the code around the class:
PHP evaluates property defaults, constant values, and enum case values as constant expressions, which cannot read a variable, and a class body sees nothing of the code that declares the class.
Cause
Scope::atwalks up from a position and keeps the first class-like and the first function-like it meets, without checking that the function-like is inside the class-like.So a position in
new class { … }inside a method pairs the anonymous class with the outer method, and takes that method's variables.A class body with no function-like around it is read as the file's global scope, and takes the file's top-level variables.
Change
Scope::atstops looking for a function-like once it has passed a class-like.Behavior
At a position in a class body outside any method, no variable from around the class is visible, so variable completion offers none of them.
$thiswas already unbound in these positions, since its type came from the class's name, and that stays true.This prepares for binding
$thisin an anonymous class's methods, which without it would also bind$thisin that class's property defaults.It is groundwork for #881.
Tests
VariableBindingsTestchecks a property default in an anonymous class inside a method, and in a class after top-level code.Known limits
Found during review, in code this pull request does not change:
$this.🤖 Generated with Claude Code