You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With a default configuration (phpcs --standard=VariableAnalysis -s phpcs-test.php), then "Variable $this is undefined. (VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable)" is reported for line 4 (the echo line), but not for the $this in the empty().
If the only function you tested with is empty(), then this is not a bug but a feature since empty() is allowed to contain undefined variables (since #204). This feature was added because both empty() and isset() are language constructs that are often used to detect the existence of variables (for example, no warning or error is thrown doing empty( $foo['bar']['baz'] ) if $foo does not exist, but will throw warnings for any other function like do_something( $foo['bar']['baz'] )).
Do you find this occurs with other functions as well?
That makes sense. I tried with current_user_can() as the wrapping function, and that correctly gave a violation, and then this was correctly silenced with the <property name="allowUndefinedVariablesInFileScope" value="true"/> line in the config file ✅
Snippet:
With a default configuration (
phpcs --standard=VariableAnalysis -s phpcs-test.php
), then "Variable $this is undefined. (VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable)" is reported for line 4 (theecho
line), but not for the$this
in theempty()
.Likewise:
...doesn't give any violation at all.
If I remove the
empty()
, then the violation is reported.Tested in VA 2.11.0.
The text was updated successfully, but these errors were encountered: