Interfaces may only include hooked properties¶
Description¶
PHP 8.4 introduced the support for properties in interfaces. Although, the properties must have a property hook, aka one associated method that deals with get
and set
operations on that property.
Example¶
<?php
interface I {
public $property;
public $propertyWithHook {
// This is an abstract property
get;
};
}
?>
Solutions¶
Add an identity hook, such as
get => $this->property = $value;
, which is the default behavior.Turn the interface into an abstract class.
Turn the interface into a trait.
In more recent PHP versions, this error message is now Interfaces may not include properties.