Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:40021 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 1649 invoked from network); 20 Aug 2008 18:39:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Aug 2008 18:39:45 -0000 Authentication-Results: pb1.pair.com header.from=pstradomski@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=pstradomski@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.128.188 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: pstradomski@gmail.com X-Host-Fingerprint: 209.85.128.188 fk-out-0910.google.com Received: from [209.85.128.188] ([209.85.128.188:43902] helo=fk-out-0910.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D2/E7-57622-EE46CA84 for ; Wed, 20 Aug 2008 14:39:43 -0400 Received: by fk-out-0910.google.com with SMTP id 18so379830fks.7 for ; Wed, 20 Aug 2008 11:39:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:reply-to:to:subject:date :user-agent:cc:references:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:message-id; bh=aCFl1fVR8UTkijFIcmHBA5brQPPjhcw1R9m7eFV4CNQ=; b=uyTryvMP3WnUmAEff2Hs+7PrakocW+Lkr1UDyzTOv9GAiNwc/WmrbsBlM8e7pSw0vu xJA+HapikbbCBwPPo6YUGY0JUk/HR1GwhG15fEuAl0MXEaaYBnrjuvzTQKiYJRJ8MhLU oRH8DGZlHNMPqdnyM1sMiJ9Ym/tdoV4YBgYYA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:reply-to:to:subject:date:user-agent:cc:references:in-reply-to :mime-version:content-type:content-transfer-encoding :content-disposition:message-id; b=prrNdTZzObhC6URuXwqKLo7ch8nUx+7cUxibrkThKrOT1/MN3PhV9pR8b9JKWB9Aid xwdSnzaDn+rypAka93qEdpOe8opNqBshH4Q04z95Ui99bUvMLtKY2V505oH4O+wQnEW7 oHXR4MTRz5AdaW4EQ5/Sib1w43NnCyRZFCqjg= Received: by 10.180.242.5 with SMTP id p5mr226362bkh.76.1219257579614; Wed, 20 Aug 2008 11:39:39 -0700 (PDT) Received: from deimos ( [91.196.215.2]) by mx.google.com with ESMTPS id y15sm1959668fkd.17.2008.08.20.11.39.37 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 20 Aug 2008 11:39:38 -0700 (PDT) Reply-To: =?utf-8?q?Pawe=C5=82_Stradomski?= To: internals@lists.php.net, Marcus Boerger Date: Wed, 20 Aug 2008 20:38:57 +0200 User-Agent: KMail/1.9.9 Cc: Volodymyr Iatsyshyn References: <8C.C1.14056.B80DAA84@pb1.pair.com> <1586387787.20080820164616@marcus-boerger.de> In-Reply-To: <1586387787.20080820164616@marcus-boerger.de> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-ID: <200808202038.57642.pstradomski@gmail.com> Subject: Re: [PHP-DEV] Annotations Request From: pstradomski@gmail.com (=?utf-8?q?Pawe=C5=82_Stradomski?=) W li=C5=9Bcie Marcus Boerger z dnia =C5=9Broda, 20 sierpnia 2008: > Hello Volodymyr, > Basically there is no need for annotations in PHP unlike there is in Pyth= on > for instance. However, while the following work: > php -r 'class T { const C=3D42; var $p=3DT::C; } var_dump(new T);' > php -r 'class T { const C=3D42; const D=3DT::C; } var_dump(new T); > the next two do not: > php -r 'class T { const C=3D42; var $p=3DT::C + 1; } var_dump(new T);' > php -r 'class T { const C=3D42; const D=3DT::C + 1; } var_dump(new T); > > So you might want to have full support for evaluated consts/default value= s. I don't really get your point. Annotations are not about constant values, b= ut=20 about adding arbitrary attributes to classes and methods/functions.=20 A simple use case (in pseudocode): class MyController extends BaseController { // www.example.com/index @allow('any') @method('get') public function index() { } // www.example.com/comment @allow('any') @method('post') public function comment() { } // www.example.com/admin @allow('admin') @method('get') public function admin() { } } class BaseController { public function _execute() { $action =3D $this->parseTheUrl(); $method =3D new ReflectionMethod($this, $action); if ($method->annotations('method') !=3D $_SERVER['REQUEST_METHOD'])= { return $this->methodNotAllowed(); } elseif (! $this->currentUser->hasPrivilege($method->annotations('allow')= ) { return $this->forbidden(); } else { return $this->$action(); } } } Python does not need annotations, as functions can have arbitrary attribute= =20 set: def a(): pass a.x =3D 5 It also has very powerful mechanism of decorators, which are basically=20 higher-order functions applied to functions on their definition, but I don'= t=20 think Volodymyr asks for so much.=20 =2D-=20 Pawe=C5=82 Stradomski