AW: [PHP-DEV] Attributes support proposal
| From: | Timm Friebe | Date: | Mon, 18 Apr 2005 15:13:44 +0000 |
| Subject: | AW: [PHP-DEV] Attributes support proposal | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-16000@lists.php.net to get a copy of this message | ||
Hi,
[...]
> I am playing around with an extension to the Zend Engine 2 to
> allow class properties and methods to be tagged with
> attributes. These attributes would then be accessible through
> the Reflection classes:
The PHP development team is usually against these kinds of OOP syntax sugar
additions, search Google / the archives for:
* Having IException as an interface instead of needing to
extend the builtin Exception class (php-internals)
* Static initializers (pear-dev)
* with() keyword (???)
* Namespaces (php-internals, zendengine2)
* Operator overloading (php-internals)
* throws clause (zendengine2)
* Passing NULL to typehints (php-internals)
* finally (php-internals)
* Return type hints (php-internals)
* self should reflect runtime class (php-internals)
* Automated getters/setters (php-internals)
(this list is by no means complete)
Having said that, how about implementing that in userland?
class Storable {
#[serializer:toString; persistent:true;]
public $date;
}
Extend (or wrap) the reflection classes and add:
MyClass::getAnnotations()
MyMethod::getAnnotations()
MyProperty::getAnnotations()
In those, parse the sourcecode with ext/tokenizer and extract all comments
beginning with the string "#[", push them into a hashmap and return it.
It's not as slow as you might expect. Of course, it'll only work if you
don't use "#[" in any other comments:)
- Timm