Hi Stas,

On Mon, May 9, 2011 at 9:35 PM, Stas Malyshev <smalys...@sugarcrm.com> wrote:
> Hi!
>
>> I updated the RFC. I may have missed one thing or two, but overall
>> idea and how code behave is there.
>> This question is answered on wiki RFC. =)
>>
>> Here is the direct link: https://wiki.php.net/rfc/annotations
>
> Some questions I didn't find the answers in the RFC:
> 1. When the annotation objects are instantiated?

Objects are only instantiated when requested (getAnnotations() or
getAnnotation())

> 2. What is permissible in the arguments of annotation - e.g. can I put any
> expression there?

You are allowed to use any scalar value + array + any object that
implements ReflectionAnnotation interface.

> 3. What <Foo(<Bar>)> actually means and how it is supposed to be parsed?

It would instantiate a class Bar and would pass it as an instance of
Foo that is also being created when doing getAnnotations() or
getAnnotation('Foo')

> 4. What happens if ctor for annotation has error/exception?

There're error support just like PHP has. Here is a sample:

Fatal error: Uncaught exception 'Exception' with message 'Fooooo' in
/src/php-src/trunk/ok.php:6
Stack trace:
#0 [internal function]: simpleannotation->__construct()
#1 /src/php-src/trunk/ok.php(15):
ReflectionClass->getAnnotation('simpleannotatio...')
#2 {main}
  thrown in /src/php-src/trunk/ok.php on line 6

Code:

class SimpleAnnotation implements ReflectionAnnotation {
    public function __construct()
    {
        throw new Exception('Fooooo');
    }
}

<SimpleAnnotation>
class Foo {
}

$r = new ReflectionClass('Foo');
var_dump($r->getAnnotation('SimpleAnnotation'));

> 5. Are there any limitations on classes that can be used as annotations?

As I said, only classes that implement ReflectionAnnotation are
allowed to be used. It gives errors if you attempt to do something
invalid.
Here is the error you get if you attempt to use a non-declared annotation:

class Foo implements ReflectionAnnotation {
    public function __construct($bar)
    {}
}

class Bar {}

<Foo(<Bar>)>
class FooBar {
}

$r = new ReflectionClass('FooBar');
var_dump($r->getAnnotations());

Fatal error: ReflectionClass::getAnnotations(): 'Bar' must implement
'ReflectionAnnotation' to act as an annotation in - on line 15


> 6. Do we need any special support for bytecode caches?

Yes. Every structure which can be annotated now will have a new member
in their C structure which is annotations, this structure is populated
at compile time and store all the metadata information. So if you have
an opcode cache the compilation will not occur, so the annotations
will be NULL. That's why the opcode cache will have to store the
annotations, so that it can be retrieved every time.

>
> --
> Stanislav Malyshev, Software Architect
> SugarCRM: http://www.sugarcrm.com/
> (408)454-6900 ext. 227
>



-- 
Guilherme Blanco
Mobile: +55 (16) 9215-8480
MSN: guilhermebla...@hotmail.com
São Paulo - SP/Brazil

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

Reply via email to