Skip to content

Squiz.Scope.StaticThisUsage incorrectly looking inside closures #1747

Closed
@WarriorXK

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.

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