Hi!

> The approach for annotations that I like best would actually be not
> annotations, but Python-style decorators. They’re very simple, but
> very powerful. They would allow you to do annotations, but also add
> extra functionality to functions.

For python-style decorators, at least the way they work in Python, we'd
need to organize our function tables differently, as Python just
replaces the function with another one while decorating, and I'm not
sure it'd be as easy to do with PHP.

> Which would be equivalent to the following PHP code:
> 
> $myfunc = function myfunc() { # function source code here }; $myfunc
> = some_decorator($myfunc, foo, bar);

Not really, because functions work differently in Python and in PHP. You
can not just replace a function in class's function table with random
closure in PHP, at least easily.
You'd have to convert all such functions to closures (or something that
can be both, maybe) and have the engine be aware that function table now
can store closures. And, also, inheritance may get a bit weird there. It
would be very powerful, but it may not be very simple to do.

Also, it is a major overkill for what annotations are commonly used -
attaching a piece of data to an entity. In Python, decorators are very
powerful for modifying function behavior (i.e., attaching pre/post
conditions to functions or doing some things phpunit does is really
easy) but it is too much for just attaching data.
-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/

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

Reply via email to