Error Identifier: property.abstractWithoutAbstractHook
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 Shape
{
abstract public string $name {
get {
return 'shape';
}
set;
}
}
Why is it reported? #
The property is declared as abstract and has hooks, but none of its hooks are actually abstract (without a body). For a property to be declared abstract, it must specify at least one abstract hook – a hook declared without a body. If all hooks have bodies, the property is not abstract.
This is a PHP language-level restriction enforced since PHP 8.4 property hooks.
How to fix it #
Make at least one hook abstract by removing its body:
abstract class Shape
{
abstract public string $name {
- get {
- return 'shape';
- }
+ get;
set;
}
}
Alternatively, remove the abstract keyword from the property if all hooks should have implementations:
-abstract class Shape
+class Shape
{
- abstract public string $name {
+ public string $name {
get {
return 'shape';
}
+ set {
+ $this->name = $value;
+ }
}
}
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\PropertyInClassRule [1]