Re: [RFC] PHP Attributes
| From: | Dmitry Stogov | Date: | Thu, 21 Apr 2016 23:26:50 +0000 |
| Subject: | Re: [RFC] PHP Attributes | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-92623@lists.php.net to get a copy of this message | ||
On 04/22/2016 02:09 AM, Colin O'Dell wrote:
A more robust alternative would be something along the same lines that Doctrine uses: Make annotations actual classes. Just spitballing here - what if both approaches were supported, but class-based annotations were prefixed with a special character (perhaps "@") to differentiate them? For example: <<ArbitraryAnnotation("Hello world")>> <<@ORM\Entity(table => "foo")>> class Foo {Current proposal doen't support this, but this may be a good idea. 1) Attribute names might be not just strings, but also namespace qualified. 2) They may be optionally prefexed by some special character. To create or not to create attribute objects is the question for next layer, but the base layer should provide necessary information. Thanks. Dmitry.// ...} namespace ORM; class Entity implements \Attribute {// ...} $r = new ReflectionClass('ORM\Entity'); var_dump($r->getAttributes()); ----- array(2) {["ArbitraryAnnotation"]=> string(11) "Hello world" ["ORM\Entity"] => object(ORM\Entity)#1 (0) { ... }} ----- Again, I'm not necessarily advocating this - just throwing the idea out there for discussion.
Regards, Colin