Error Identifier: property.hooksNotSupported
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 Foo
{
public string $name {
get => $this->name;
set => $this->name = $value;
}
}
Why is it reported? #
Property hooks (get/set hooks) are only supported on PHP 8.4 and later. The analysed code uses property hooks, but the project’s configured PHP version is older than 8.4.
How to fix it #
If your project needs to support PHP versions older than 8.4, use getter and setter methods instead:
<?php declare(strict_types = 1);
class Foo
{
- public string $name {
- get => $this->name;
- set => $this->name = $value;
- }
+ private string $name;
+
+ public function getName(): string
+ {
+ return $this->name;
+ }
+
+ public function setName(string $value): void
+ {
+ $this->name = $value;
+ }
}
Or update the PHP version requirement for your project to PHP 8.4 or later.
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]