-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
False-positive UndefinedVariable
for static variable inside an anonymous function
#277
Comments
It looks like this is happening because the code that detects if a variable is inside a list of function call arguments is incorrectly finding the static variable. phpcs-variable-analysis/VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php Line 1337 in 9f70390
|
This should be fixed by #279 However, I wanted to ask, @shvlv: in your examples, would you expect those static variables to produce no warnings at all? For example, add_action('hook', static function (): void {
static $providerId;
}); In this code, |
Thanks, @sirbrillig!
Yes, there was a minimum reproducible example. So
I've tested your code. It works nicely for add_action('test', function () {
static $providerId;
}); |
Ohhh... thanks. I bet it's because in that case, |
I stumbled upon the behavior when using the following code:
It causes
Variable $providerId is undefined. (VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable)
For my tests the minimum reproducible snippet was
It seems round brackets do matter.
Thanks for maintaining a very useful library!
The text was updated successfully, but these errors were encountered: