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

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to