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 HasValue
{
public int $value { get; }
}
class Foo implements HasValue
{
private int $stored = 0;
public int $value {
set {
$this->stored = $value;
}
}
}
Why is it reported? #
When a child class overrides a property from a parent class or interface, it must preserve the readability contract. If the parent property is readable (has a get hook or is a regular property), the overriding property must also be readable. Removing readability from an overriding property would break the Liskov Substitution Principle – code that expects to read the property based on the parent type would fail.
In the example above, the interface HasValue declares $value as readable (get), but the implementing class defines only a set hook that stores to a different field. This makes the property virtual and write-only, violating the readability contract.
This rule applies to PHP 8.4+ property hooks.
How to fix it #
Add a get hook to the overriding property so it remains readable:
class Foo implements HasValue
{
private int $stored = 0;
public int $value {
+ get {
+ return $this->stored;
+ }
set {
$this->stored = $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\OverridingPropertyRule [1]