Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:49724 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 42076 invoked from network); 16 Sep 2010 19:02:12 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Sep 2010 19:02:12 -0000 Authentication-Results: pb1.pair.com smtp.mail=christian.kaps@mohiva.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=christian.kaps@mohiva.com; 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:35481] helo=zucker.schokokeks.org) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A0/9C-15036-1B9629C4 for ; Thu, 16 Sep 2010 15:02:11 -0400 Received: from [192.168.178.2] (p57B53D6A.dip.t-dialin.net [::ffff:87.181.61.106]) (AUTH: PLAIN christian.kaps@mohiva.com, SSL: TLSv1/SSLv3,256bits,CAMELLIA256-SHA) by zucker.schokokeks.org with esmtp; Thu, 16 Sep 2010 21:02:06 +0200 id 0000000000018007.000000004C9269AE.00004238 Message-ID: <4C9269AE.5090102@mohiva.com> Date: Thu, 16 Sep 2010 21:02:06 +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: internals@lists.php.net CC: weierophinney@php.net References: <39505F13-655A-43AF-941E-77750B7F7201@gmail.com> <001601cb543a$d81ebac0$885c3040$@com> <4C8FC695.2060800@sugarcrm.com> <4C8FD72B.1070108@sugarcrm.com> <4C905A99.9050802@mohiva.com> <59.22.15036.9AF329C4@pb1.pair.com> In-Reply-To: <59.22.15036.9AF329C4@pb1.pair.com> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Re: Re: PHP Annotations RFC + Patch From: christian.kaps@mohiva.com (Christian Kaps) Am 16.09.2010 18:02, schrieb Matthew Weier O'Phinney: > >> in my mind there is a big mistake when using annotations in PHPDoc comments. > What is the mistake? You don't explain that anywhere in your reply -- you simply > give code examples of how you feel they should work. > For me the mistake is that annotation classes must be defined with their FQN or you must create an alias for the namespace. This alias must be registered before using this annotations. Every framework I use uses its own rules for defining annotatations, registering annotation namespaces and so on. For me this is impractical. Registering the namespace with the out of the box PHP use statement is for me the better way. I thought this was clear from my comparison. >> An other problem is that every framework use its one annotation syntax. >> So it makes the framework end user more confusing as using a clear >> unique syntax. > Actually, I see this as a _benefit_ or _feature_ of such an approach -- itwer ist den dir auf den schlips getreten > allows developers to define their own annotations, which allows them to create > new approaches. We see this already in docblock annotations -- PHPUnit makes use > of them (@expectedException, @group, etc.). Groups like the Framework Interop > Group can tackle standard use cases. This isn't what I meant with different syntax. Different syntax for me is: [Annotation([1, 2, 3])] @Annotation({1, 2, 3}) %Annotation(array(1, 2, 3)) Have fun, using annotations from different frameworks for one and the same method, property or class. >> I think the PHP way should be as in the next example. >> >> namespace my\project\models\dto; >> >> use com\jsr303\validator\constraints\NotNull; >> use com\jsr303\validator\constraints\Integer; >> use com\jsr303\validator\constraints\Regexp; >> use com\jsr303\validator\constraints\MinLength; >> use com\jsr303\validator\constraints\MaxLength; >> use my\project\validator\constraints\Zipcode; >> >> class User { >> >> [NotNull] >> [Integer] >> public $id; > This is entirely unclear to me. Will it type-cast to integers? will it throw an > exception for null values? I actually don't know what this code will do -- which > brings me to my chief issue so far with this debate: annotations, since they are > meant to be "machine-readable" (that's what all the proponents are saying, > anyways), introduce a huge WTF factor when debugging -- is it the code that > caused an exception? If not, was it an annotation? Which one? what input did it > get? etc. > If an annotation throws an exception because of syntax errors you get an stack trace. So it should not be a problem to localize this error. In this example the annotations doesn't throw any exceptions. $user = new User; $user->id = 'only integers are allowed'; $validator = new Validator(); $results = $validator->validate($user); The result contains a constraint violation message. For more you can look at the Hibernate Validator page. http://www.hibernate.org/subprojects/validator.html >> With this out of the box PHP annotations it makes it possible to create >> powerful frameworks which can used by a great range of developers >> without learning a new syntax for it. Pleas do not argue about thy >> syntax of the annotation because this isn't final. > Um, you're being contradictory here -- you're actually _suggesting_ a brand new > syntax, which leads to the exact opposite of what you assert. I meant that this developers who using this frameworks must not learn different syntaxes but rather one. > Using existing > docblocks and adding an annotations parser to it would be using existing syntax. > - How would you comment out an annotation in a doc block? - How would you define annotations with namespaces? - Parsing of annotations is slow. When using caching every framework that I use implements other caching rules for its annotations. There are many more reasons mentioned in all the mails. You may excuse me because I am not an native English speaker so it can be be the case the one or the other formulation isn't correct. Greetings, Christian