Hello Volodymyr,
Tuesday, August 19, 2008, 3:54:16 PM, you wrote:
> Hi,
> Is there a chance to have annotations like in Java or like .NET attributes?
> Now, I use Java Annotations emulation, through Reflections and PHPDoc
> blocks. Example:
> /** Annotation One*/
> class DemoAnnotation1 extends C01t_Annotation
> {
> public $value;
> }
> /** Annotation Two*/
> class DemoAnnotation2 extends C01t_Annotation
> {
> public $p1;
> public $p2;
> }
> class DemoClass
> {
> const SOME_CONST = 5;
> /** @DemoAnnotation1(DemoClass::SOME_CONST + 1) */
> public $property1;
> /** @DemoAnnotation2(p1 => 1, p2 => 'Hello, Word!') */
> public $property2;
> }
Basically there is no need for annotations in PHP unlike there is in Python
for instance. However, while the following work:
php -r 'class T { const C=42; var $p=T::C; } var_dump(new T);'
php -r 'class T { const C=42; const D=T::C; } var_dump(new T);
the next two do not:
php -r 'class T { const C=42; var $p=T::C + 1; } var_dump(new T);'
php -r 'class T { const C=42; const D=T::C + 1; } var_dump(new T);
So you might want to have full support for evaluated consts/default values.
The reason why we do not support this right now is a limitation in how
consts and default values get initialised.
Best regards,
Marcus
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php