Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:49604 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 24598 invoked from network); 12 Sep 2010 08:30:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Sep 2010 08:30:56 -0000 Authentication-Results: pb1.pair.com header.from=christian.kaps@mohiva.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=christian.kaps@mohiva.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain mohiva.com designates 78.46.69.5 as permitted sender) X-PHP-List-Original-Sender: christian.kaps@mohiva.com X-Host-Fingerprint: 78.46.69.5 zucker.schokokeks.org Received: from [78.46.69.5] ([78.46.69.5:57949] helo=zucker.schokokeks.org) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 43/30-17717-FBF8C8C4 for ; Sun, 12 Sep 2010 04:30:55 -0400 Received: from [192.168.178.2] (p57B57F94.dip.t-dialin.net [::ffff:87.181.127.148]) (AUTH: PLAIN christian.kaps@mohiva.com, SSL: TLSv1/SSLv3,256bits,CAMELLIA256-SHA) by zucker.schokokeks.org with esmtp; Sun, 12 Sep 2010 10:30:52 +0200 id 0000000000018008.000000004C8C8FBC.000055F5 Message-ID: <4C8C8FBC.3090007@mohiva.com> Date: Sun, 12 Sep 2010 10:30:52 +0200 User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.8) Gecko/20100903 Lightning/1.0b2pre Thunderbird/3.1.2 MIME-Version: 1.0 To: Stas Malyshev CC: Pierre Joye , Guilherme Blanco , Pierrick Charron , "internals@lists.php.net" References: <4C873C0F.1010200@zend.com> <4C879613.7090709@zend.com> <4C887D2B.2000605@zend.com> <4C8AC526.7000505@sugarcrm.com> <4C8B6168.30504@mohiva.com> <4C8BC81E.8000605@sugarcrm.com> <4C8C073F.402@sugarcrm.com> In-Reply-To: <4C8C073F.402@sugarcrm.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Re: PHP Annotations RFC + Patch From: christian.kaps@mohiva.com (Christian Kaps) Hi Stas, this type of annotations cannot be used as PHPDoc annotations due its different syntax. In other languages like Java, C# or AS3 annotations are an independent language construct and I think in PHP it should be the same. I dont know how many non-performant user-land implementations(hacks), with different syntaxes and concepts, exists in the meantime. So I think it is time for a consistent syntax in the PHP core. I see your concerns about the inconsistency in the syntax, so here are my thoughts how we can avoid this. 1. In Java annotations are a special type of an interface. But due the lack of type hinting for scalar values we cannot use this construct, because we cannot put some validation logic in an interface. My proposal is to create a new "annotation" type. This type should have the same rules as a class and should contain all features proposed in the ReflectionAnnotation class. With this construct it should be possible to use named or unnamed parameters for an annotation. annotation URL { public $url; public $title; public $target; public function __construct($url, $title, $target = 'self') { } } [URL('http://www.php.net', 'PHP', 'blank')] or [URL('http://www.php.net', 'PHP')] or [URL('url' = 'http://www.php.net', 'name' = 'PHP', 'target' = 'blank')] With this new type there exists a new language construct which doesn't overlap with the class construct. So it is possible to use its own instantiation syntax. 2. The syntax for arrays should be the same as in PHP. So we can use the [] as annotation separator. When we allow expressions in the form Annotation(array('value' => 4 %2)) or Annotation(array('value' => !MY_CONSTANT)) which I think is a valid construct, then we cannot use the ! or % as annotation separator. 3. For the consistency with named parameters there exists 2 possibilities. Either we implement named parameters in the PHP core or named parameters are an exception for annotations. I think with this changes we have a separate language construct like traits, which does allow a new syntax. Greetings, Christian Am 12.09.2010 00:48, schrieb Stas Malyshev: > Hi! > >> It seems that there is a misunderstanding about the goals of the >> annotations. They are not meant to be read by human being >> (javadoc/phpdoc/etc. are) but to be parsed automatically to be used >> for services. > > If it's for services/phpdoc, why can't it be part of phpdoc? > > I see here a whole new language syntax being invented, complete with > nested constructs, new instantiation syntax, new argument parsing > rules and what not. All that while tiniest attempts on introducing > syntax sugar were consistently rejected. But here we have sub-section > of language with totally different rules - PHP has no named > parameters, but annotations have them, PHP has no array/instantiation > shortcut syntax, but annotations have it, etc. Please understand, I'm > not objecting to a particular detail of syntax - I'm objecting to the > fact that the design of the language appears to be guided by a random > whim.