Error Identifier: property.abstractInInterface
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);
interface HasName
{
abstract public string $name { get; } // ERROR: Property in interface cannot be explicitly abstract.
}
Why is it reported? #
Properties declared in interfaces are implicitly abstract, similar to how interface methods are implicitly abstract. Adding the abstract keyword explicitly is redundant and not allowed by PHP. All interface properties with hooks are already required to be implemented by classes that implement the interface.
How to fix it #
Remove the abstract keyword from the property declaration:
<?php declare(strict_types = 1);
interface HasName
{
- abstract public string $name { get; }
+ public string $name { get; }
}
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\Properties\PropertiesInInterfaceRule [1]