Skip to content

[Feature request] Consider rule for calling static methods non-statically #514

@Majkl578

Description

@Majkl578

Based on a discussion under a commit that converts $this->assert*() to self::assert*() in Doctrine: doctrine/dbal@62eb475#commitcomment-24420550

PHP still allows calling static method non-statically, although such behavior could be considered unsafe and not a good practice. Hopefully PHP will come to a point where this behavior will be deprecated.

Example:

class Test
{
	public function foo() : void
	{
		$this->bar();
	}
	
	public static function bar() : void
	{
	}
}

This currently works, PHP has no problems with mixing static and non-static calls (sadly). Also PHPStan is happy.

I'd like to propose a new rule that would ban this abomination altogether. 🥇 I'd love to see it in core in L5/L6 for example, but if it's too agressive (some people may think so), at least to be included in the upcoming phpstan-extra-strict-rules repo.

Thoughts?

cc-ing @PowerKiKi & @Ocramius from the abovementioned discussion.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions