The return type AttributesAware is a trait, and thus cannot be used for type-hinting in PHP. Maybe consider adding an interface and use that for type-hinting?
In PHP traits cannot be used for type-hinting as they do not define a well-defined
structure. This is because any class that uses a trait can rename that trait’s methods.
If you would like to return an object that has a guaranteed set of methods, you
could create a companion interface that lists these methods explicitly.
Loading history...
42
*/
43
public function setAttribute(string $name, string $value): self
44
{
45
$this->attributes[$name] = new Attribute($name, $value);
In PHP traits cannot be used for type-hinting as they do not define a well-defined structure. This is because any class that uses a trait can rename that trait’s methods.
If you would like to return an object that has a guaranteed set of methods, you could create a companion interface that lists these methods explicitly.