website/errors/property.hookedStatic.md
<?php declare(strict_types = 1);
class Foo
{
public static string $name { // ERROR: Hooked properties cannot be static.
get => 'hello';
}
}
PHP does not allow property hooks on static properties. Property hooks (get and set) are designed to work with instance properties and rely on $this context. Static properties belong to the class rather than to an instance, so hooks are not supported for them.
If the property needs hooks, make it an instance property:
<?php declare(strict_types = 1);
class Foo
{
- public static string $name {
+ public string $name {
get => 'hello';
}
}
If the property needs to be static, remove the hooks and use a static method instead:
<?php declare(strict_types = 1);
class Foo
{
- public static string $name {
- get => 'hello';
- }
+ public static string $name = 'hello';
}