doc-en
doc-en copied to clipboard
Use Attrbiute on intrerface
I don't find any documentation about using Attribute on interfaces
Example:
<?php
#[\Attribute]
final readonly class TestAttribute
{}
#[TestAttribute]
interface TestInterface {}
final readonly Test implements TestInterface {}
// If i try get class attribute with reflection
$t = new Test;
$r = new \ReflectionClass($t);
echo count($r->getAttributes()); // Display 0
And its valid using or not?
Attributes are not inherited, so if you define TestAttribute on the interface then you must call getAttributes on that interface directly. You can, of course, use methods like getParentClass and getInterfaces to "discover" all attributes of a class.
https://3v4l.org/A1a7q
I do not see this mentioned in the documentation. Do you have a suggestion on how to add it?