Skip to content

Squiz.Scope.StaticThisUsage incorrectly looking inside closures #1747

Closed

Description

@WarriorXK

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.

Activity

  1. changed the title [-]Squiz.Scope.StaticThisUsageSniff in Closures[/-] [+]Squiz.Scope.StaticThisUsage incorrectly looking inside closures[/+] on Nov 29, 2017
  2. added a commit that references this issue on Nov 29, 2017
  3. gsherwood commented on Nov 29, 2017

    @gsherwood
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions