Skip to content
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

Squiz.Scope.StaticThisUsage incorrectly looking inside closures #1747

Closed
WarriorXK opened this issue Nov 10, 2017 · 1 comment
Closed

Squiz.Scope.StaticThisUsage incorrectly looking inside closures #1747

WarriorXK opened this issue Nov 10, 2017 · 1 comment

Comments

@WarriorXK
Copy link

WarriorXK commented Nov 10, 2017

Currently the StaticThisUsageSniff shows an error in the following case:

<?php

class A {
    static public function Test() {
        return function() {
            echo($this->_name . PHP_EOL);
        };
    }
}

class B {

    protected $_name = 'Bob';

}

$closure = A::Test();
$b = new B();

$closure = $closure->bindTo($b, B::class);
$closure();

The sniff should either not error or downgrade it to a warning if the $this reference is inside a closure.

@gsherwood gsherwood changed the title Squiz.Scope.StaticThisUsageSniff in Closures Squiz.Scope.StaticThisUsage incorrectly looking inside closures Nov 29, 2017
@gsherwood
Copy link
Member

No error should be reported - the sniff wasn't skipping the closure like it should have been. I think it might actually pre-date closures. It was a bit of a mess too, so I cleaned it up.

Thanks for reporting this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants