Skip to content

Latest commit

 

History

History
37 lines (27 loc) · 623 Bytes

Squiz.Scope.StaticThisUsage.md

File metadata and controls

37 lines (27 loc) · 623 Bytes

Pattern: Use of $this in static method

Issue: -

Description

Checks for usage of $this in static methods, which will cause runtime errors.

Example

Example of incorrect code:

class SomeClass
{
    static function test()
    {
		return $this->$staticMember;
    }
}

Example of correct code:

class SomeClass
{
    static function test()
    {
        return self::$staticMember;
    }
}

Further Reading