Skip to content

New rule to disallow use self:: for non-static method calls #1845

Description

@f1mishutka

Please add new rule to disallow use self:: for non-static method calls ($this-> should be used instead).

Example:

class SomeClass
{
  public function NonStaticMethod(): void
  {
    //do something
  }
  
  public function AnotherMethod(): void
  {
	$this->NonStaticMethod(); //normal way to call non-static methods
	
	self::NonStaticMethod(); // This is where sniff should raise error
  }
}

Using self:: to call non-static methods is formally acceptable in PHP, but is a marker of some leftovers after refactoring or just a bad design.

Thank you for the great product!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions