[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-internals
Subject:    Re: [PHP-DEV] Re: Re: PHP Annotations RFC + Patch
From:       Jussi Vaihia <jussiava () gmail ! com>
Date:       2010-09-16 20:58:52
Message-ID: AANLkTin6He9FGWtTmwSwTZsb7saDG_cajwa1rxSXbvAf () mail ! gmail ! com
[Download RAW message or body]

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
>

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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic