Good reminder, thanks! Implementation would indeed require support from PHP, say:
// magic-method __decorate implies that __construct would return $this->__decorate(func_get_args(), $f); and enforce @ as annotation-syntax class Dec1 { function __decorate($args, $f) { return $f; } } class Dec2 { ... } @dec2 @dec1 function foo() {} means this: $foo = new Dec2(new Dec1(new ReflectionFunction('foo'))); Perhaps ... $foo = @Dec2(@Dec1(new ReflectionFunction('foo'))); On Thu, Sep 16, 2010 at 8:49 PM, Stas Malyshev <smalys...@sugarcrm.com> wrote: > Hi! > >> Could PHP as a language be kept "pure" by first implementing python >> decorators*, then implement annotations using a purpose-built >> decorator? > > No, we can't have python decorators because unlike Python PHP functions and > classes aren't first-class objects. In Python, this: > > @dec2 > @dec1 > def func(arg1, arg2, ...): > pass > > means this: > > def func(arg1, arg2, ...): > pass > func = dec2(dec1(func)) > > However, you can't write equivalent code in PHP. > -- > Stanislav Malyshev, Software Architect > SugarCRM: http://www.sugarcrm.com/ > (408)454-6900 ext. 227 > -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php