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
FILE: /tmp/PHPCompatibility/example.php
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
9 | WARNING | Closures / anonymous functions only have access to $this if used within a class or when bound to an object using bindTo(). Please verify.
| | (PHPCompatibility.FunctionDeclarations.NewClosure.ThisFoundOutsideClass)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FYI: it's not even just anonymous classes... looks like named classes and other closed structures can all be declared within a closure: https://3v4l.org/Zb22K
FYI: it's not even just anonymous classes... looks like named classes and other closed structures can all be declared within a closure: https://3v4l.org/Zb22K
Ah, cool. Learn something new every day. 😄
jrfnl
changed the title
ThisFoundOutsideClass fires false-negative on anonymous classThisFoundOutsideClass fires false-positive on anonymous class
Jan 31, 2024
Bug Description
The sniff
ThisFoundOutsideClass
fires a false-positive on$this
when nested inside an anonymous class and a closure.Given the following reproduction scenario
The issue happens when running this command:
... over a file containing this code:
with the built-in ruleset.
I'd expect the following behaviour
Pass
Instead this happened
Environment
develop
(circa 4576a17)Additional Context (optional)
This issue was pointed out to me as totten/civix#294. I can see it happening, so I'm forwarding it along with a tighter description.
Tested Against
develop
branch?develop
branch of PHPCompatibility.The text was updated successfully, but these errors were encountered: