> On 4 Nov 2014, at 18:27, Stas Malyshev <smalys...@sugarcrm.com> wrote: > > 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.
Are you sure this would be difficult? We could create a closure of the class method (trivial to do), pass it to a userland function upon creating the class (the former is easy, the “upon creating the class” is the issue), and use the closure it returns as the class method. There’d be issue with autoloading to iron out, but I don’t think it’d be a problem. > 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. A closure is just a normal function, actually. The Closure class just wraps a zend_function and a this pointer. There’s no reason you couldn’t substitute here. I believe you could literally just copy the zend_function across, though there’d obviously be some complications. Not sure about inheritance. > 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. This is useful for merely attaching data as well (just return the function passed), but it also enables manipulating the function. It could replace some cases of merely attaching data, too, by making the function do something itself, rather than having something else do something if a function has a certain annotation, when calling that function (if that makes any sense). -- Andrea Faulds http://ajf.me/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php