Error Identifier: property.abstractFinal
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);
abstract class Foo
{
abstract final public string $name { get; } // ERROR: Property cannot be both abstract and final.
}
Why is it reported? #
A property (or its hook) cannot be both abstract and final. The abstract modifier requires subclasses to provide an implementation, while final prevents subclasses from overriding it. These two modifiers are mutually exclusive and combining them is a contradiction that PHP does not allow.
This also applies when an abstract property has a final hook without a body.
How to fix it #
Remove one of the conflicting modifiers. If the property should be overridden by subclasses, keep abstract:
<?php declare(strict_types = 1);
abstract class Foo
{
- abstract final public string $name { get; }
+ abstract public string $name { get; }
}
If the property should not be overridden, provide an implementation and use final:
<?php declare(strict_types = 1);
-abstract class Foo
+class Foo
{
- abstract final public string $name { get; }
+ final public string $name {
+ get => 'default';
+ }
}
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.