Re: [RFC] Attributes v2
| From: | Saif Eddin Gmati | Date: | Tue, 10 Mar 2020 06:27:55 +0000 |
| Subject: | Re: [RFC] Attributes v2 | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-108938@lists.php.net to get a copy of this message | ||
Really excited to see the discussion about this feature being brought up again, thanks for working
on this :)
One thing I would suggest is to add a base interface
Attribute and multiple
sub-interfaces such as ClassAttribute, MethodAttribute, and
PropertyAttribute just like hack lang ( https://docs.hhvm.com/search?term=HH%20Attribute
)
This allows one to declare attributes that can only be used with classes ( e.g
ORM\Entity ), so PHP and check against them at runtime and throws an error when an
attribute is used in the wrong place.
```php
namespace ORM {
class Entity implements \ClassAttribute { ... }
}
namespace Foo {
use ORM;
<<ORM\Entity(...)>> // <-- Error
function bar(): void {}
}
```
I also question whether the following syntax would be supported:
```php
<<ORM\Entity(...), ORM\Table(...)>>
class Use {...}
```
I'm really looking forward to this since it can help bring more features into PHP such as :
- https://docs.hhvm.com/hack/attributes/predefined-attributes#__entrypoint
- https://docs.hhvm.com/hack/attributes/predefined-attributes#__memoize
- https://docs.hhvm.com/hack/attributes/predefined-attributes#__sealed
Regards.