Re: Re: Re: PHP Annotations RFC + Patch
| From: | Jussi Vaihia | Date: | Thu, 16 Sep 2010 20:58:52 +0000 |
| Subject: | Re: Re: Re: PHP Annotations RFC + Patch | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-49735@lists.php.net to get a copy of this message | ||
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 <smalyshev@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
>