Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78680 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 22063 invoked from network); 4 Nov 2014 20:18:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Nov 2014 20:18:47 -0000 Authentication-Results: pb1.pair.com smtp.mail=guilhermeblanco@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=guilhermeblanco@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.180 as permitted sender) X-PHP-List-Original-Sender: guilhermeblanco@gmail.com X-Host-Fingerprint: 209.85.223.180 mail-ie0-f180.google.com Received: from [209.85.223.180] ([209.85.223.180:52629] helo=mail-ie0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5F/63-02095-6A439545 for ; Tue, 04 Nov 2014 15:18:46 -0500 Received: by mail-ie0-f180.google.com with SMTP id y20so8435047ier.11 for ; Tue, 04 Nov 2014 12:18:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=3f2x1eSgpVuYpFfFfvxWPJWwUnvpLfT4p3slZi5uhMQ=; b=wNZZs7APWrMaZMAM5VYKfMurvKuZA+KAR5h+hBsh9OikzYPzSfhpQOlyQktBheqSzd PdwnEWWdv6RVm+I8O5M0pBNPL38tY4hHAfDMAbnQVAu4kD/jK8CPQOqVh1bck8AoKujl WvmYTfw8fHDr+457usm5OorfLU2VaXELoxsVNHXlFf4VZN8CIxB7dOr4K9O343+6PmN7 18r06gToTnYJkSV5IjE2t92NPECw0P0f2Cu4VVyN/rY082d2ScvYPY2QOtVgknGDtWMR RnUzFPsn8OzXpof1NKWqhPuBHRki5fJ5/oYgilEGrym/4tIeW7zsWe8cEmtZxhHSkxac 50Uw== X-Received: by 10.50.136.134 with SMTP id qa6mr26753528igb.2.1415132323756; Tue, 04 Nov 2014 12:18:43 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.155.5 with HTTP; Tue, 4 Nov 2014 12:18:23 -0800 (PST) In-Reply-To: <967E30E5-71CB-40F8-9AE2-733D327DE197@ajf.me> References: <5457AF2F.90808@php.net> <5457BDB7.8070701@garfieldtech.com> <54589A8D.3020607@sugarcrm.com> <1C3F4FA3-ABD5-4F6F-A898-F63AC1C723D5@ajf.me> <54591A76.8070302@sugarcrm.com> <967E30E5-71CB-40F8-9AE2-733D327DE197@ajf.me> Date: Tue, 4 Nov 2014 15:18:23 -0500 Message-ID: To: Andrea Faulds Cc: Stas Malyshev , Benjamin Eberlei , Pierre Joye , Levi Morrison , PHP internals , Larry Garfield Content-Type: multipart/alternative; boundary=089e0141a8dc77c0d705070e2b82 Subject: Re: [PHP-DEV] Annotation PHP 7 From: guilhermeblanco@gmail.com ("guilhermeblanco@gmail.com") --089e0141a8dc77c0d705070e2b82 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi, As one of the original authors of both Doctrine Annotations and previous RFC of native Annotations in PHP, I can go thoroughly on every specific detail about challenges of design decisions to make. Primarily, I do not see docblocks as the right place to store class' metadata information. Metadata !=3D Comments. This brings the next piece of the puzzle. We have to update lexical and semantical understanding of PHP. Taking Java's approach (@) does not work in PHP, because it conflicts with error supression. Same thing happened for {}. When Pierrick and I wrote the RFC, [] was not supported, so likely it'll break parsing too now, but at that point, we got [] to work. Ultimately, we chose <> to avoid headaches. After that, we entered on how we could semantically validate arguments. We could easily create an array declaration (as Benjamin suggested), but that would become near to impossible for a large system to figure it out where it was the problem, the small made typo. The solution was to instantiate classes (or what we folded during development, a special class type, annotation), because we could validate semantically not only classes, but also properties. We could also implement annotation targets (something can only be used in a method or at the class level). This is a valid thing to consider... more effort to the language means less efforts from end-users (consumers). Bringing annotation targeting, semantical validation was a great addiction to the RFC, because it makes easier to developers find bugs, but it exposed another set of problems (and their solutions): 1- How to instantiate them? We dropped "new" necessity under that scope and used <>. Again, it made more sense to specialize class definition into a new type (annotation), but we kept same implementation for simplicity. 2- How to consume on Reflection? We decided to use it by fetching based on class name. This added the enforcement of only having 1 instance of a class per annotation context. 3- How to partially attribute class properties while others rely on convention over configuration? We had to bring named parameters to fix this. 4- How to deal with nested Annotations? When we dropped "new", it became easy to support them by using <>. Despite any decision, inheritance is also a problem to solve. Should it clear everything out if a method is overwritten? Should a class require redeclaration of everything? This adds complexity and error-prone situations. What if everything gets inherited by default? Well, then we need a way to remove other previously declared items. We came up with the solution to just clear them until we got into further discussion. We had an Override patch that would inherit everything by default and with Override it would clear any previously declared Annotations too based on discussion's result. I hope that gives a but more insight on how RFC Annotations reached that level of maturity. Cheers, On Tue, Nov 4, 2014 at 1:58 PM, Andrea Faulds wrote: > > > On 4 Nov 2014, at 18:27, Stas Malyshev wrote: > > > > For python-style decorators, at least the way they work in Python, we'd > > need to organize our function tables differently, as Python just > > replaces the function with another one while decorating, and I'm not > > sure it'd be as easy to do with PHP. > > Are you sure this would be difficult? We could create a closure of the > class method (trivial to do), pass it to a userland function upon creatin= g > the class (the former is easy, the =E2=80=9Cupon creating the class=E2=80= =9D is the issue), > and use the closure it returns as the class method. There=E2=80=99d be is= sue with > autoloading to iron out, but I don=E2=80=99t think it=E2=80=99d be a prob= lem. > > > You'd have to convert all such functions to closures (or something that > > can be both, maybe) and have the engine be aware that function table no= w > > can store closures. And, also, inheritance may get a bit weird there. I= t > > would be very powerful, but it may not be very simple to do. > > A closure is just a normal function, actually. The Closure class just > wraps a zend_function and a this pointer. There=E2=80=99s no reason you c= ouldn=E2=80=99t > substitute here. I believe you could literally just copy the zend_functio= n > across, though there=E2=80=99d obviously be some complications. > > Not sure about inheritance. > > > Also, it is a major overkill for what annotations are commonly used - > > attaching a piece of data to an entity. In Python, decorators are very > > powerful for modifying function behavior (i.e., attaching pre/post > > conditions to functions or doing some things phpunit does is really > > easy) but it is too much for just attaching data. > > This is useful for merely attaching data as well (just return the functio= n > passed), but it also enables manipulating the function. It could replace > some cases of merely attaching data, too, by making the function do > something itself, rather than having something else do something if a > function has a certain annotation, when calling that function (if that > makes any sense). > > -- > Andrea Faulds > http://ajf.me/ > > > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --=20 Guilherme Blanco MSN: guilhermeblanco@hotmail.com GTalk: guilhermeblanco Toronto - ON/Canada --089e0141a8dc77c0d705070e2b82--