Error Identifier: interfaceExtends.class
Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.
Code example #
<?php declare(strict_types = 1);
class SomeClass
{
}
interface MyInterface extends SomeClass // ERROR: Interface MyInterface extends class SomeClass.
{
}
Why is it reported? #
An interface is attempting to extend a class using the extends keyword. In PHP, interfaces can only extend other interfaces. Classes cannot be used in an interface’s extends clause. This is a language-level constraint that will cause a fatal error at runtime.
How to fix it #
If the class implements an interface, extend that interface instead:
<?php declare(strict_types = 1);
+interface SomeInterface
+{
+ public function doSomething(): void;
+}
+
-class SomeClass
+class SomeClass implements SomeInterface
{
+ public function doSomething(): void
+ {
+ }
}
-interface MyInterface extends SomeClass
+interface MyInterface extends SomeInterface
{
}
If the intent is to define a contract, declare the required methods directly on the interface:
<?php declare(strict_types = 1);
-interface MyInterface extends SomeClass
+interface MyInterface
{
+ public function doSomething(): void;
}
Non-ignorable error #
This error cannot be ignored using @phpstan-ignore or the ignoreErrors configuration. Non-ignorable errors indicate code that would cause a crash or a fatal error at runtime, or a fundamental problem in the analysed code that must be addressed.
Rules that report this error #
- PHPStan\Rules\Classes\ExistingClassesInInterfaceExtendsRule [1]