Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:40015 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 44104 invoked from network); 20 Aug 2008 14:46:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Aug 2008 14:46:22 -0000 Authentication-Results: pb1.pair.com smtp.mail=helly@php.net; spf=unknown; sender-id=unknown Authentication-Results: pb1.pair.com header.from=helly@php.net; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 85.214.94.56 as permitted sender) X-PHP-List-Original-Sender: helly@php.net X-Host-Fingerprint: 85.214.94.56 aixcept.net Linux 2.6 Received: from [85.214.94.56] ([85.214.94.56:47616] helo=h1149922.serverkompetenz.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FD/53-51571-D3E2CA84 for ; Wed, 20 Aug 2008 10:46:22 -0400 Received: from MBOERGER-ZRH (unknown [193.142.125.1]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by h1149922.serverkompetenz.net (Postfix) with ESMTP id 4D00E11DB15; Wed, 20 Aug 2008 16:46:18 +0200 (CEST) Date: Wed, 20 Aug 2008 16:46:16 +0200 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <1586387787.20080820164616@marcus-boerger.de> To: Volodymyr Iatsyshyn CC: internals@lists.php.net In-Reply-To: <8C.C1.14056.B80DAA84@pb1.pair.com> References: <8C.C1.14056.B80DAA84@pb1.pair.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Annotations Request From: helly@php.net (Marcus Boerger) 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