Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92836 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 5266 invoked from network); 27 Apr 2016 11:58:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Apr 2016 11:58:33 -0000 Authentication-Results: pb1.pair.com smtp.mail=pierrick@webstart.fr; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=pierrick@webstart.fr; sender-id=unknown Received-SPF: error (pb1.pair.com: domain webstart.fr from 209.85.161.180 cause and error) X-PHP-List-Original-Sender: pierrick@webstart.fr X-Host-Fingerprint: 209.85.161.180 mail-yw0-f180.google.com Received: from [209.85.161.180] ([209.85.161.180:36859] helo=mail-yw0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 73/A4-20013-769A0275 for ; Wed, 27 Apr 2016 07:58:32 -0400 Received: by mail-yw0-f180.google.com with SMTP id o66so74442401ywc.3 for ; Wed, 27 Apr 2016 04:58:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=webstart-fr.20150623.gappssmtp.com; s=20150623; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc; bh=3rvSudIeJ8L+4bBBGbEh16PsH+J8ZapscnwguIp/TFU=; b=vo+zeMNCMQhqLu6cfs1l1E9PaJ1RCYXpcTDkckYdhCMBAWvjk5cDeZaJCm5OHEaY8X WKbRTi7D3hI3MDpPqjuLCjMGUduaURQsvbJXN87si22BAYm+Kq0XJtfMwanYnAMo5T8o EPsGHRMXXjci4pwUXDFUwMbY+kBf7ytDQ9wVl7HriVzGVdyscYAlgfwq3Zm8+/9PC4uU /6MNX2AQWA+/DzrRakIU7wTCyRlgWfO6mGidpMcQn4jYNQ3ydTln/KWXaRsKoPvupuOy kSACxVNXekZf3nT5M4rfDCPKPxitBSM+fql2SEiGoHjGq9YPD1R3XH7nR+VOQhB46k62 rAWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:date :message-id:subject:from:to:cc; bh=3rvSudIeJ8L+4bBBGbEh16PsH+J8ZapscnwguIp/TFU=; b=YnlaPMCIPAe47sBU+c4sdBZV0b9flm4YvUJSSByNJcDgCeVf+JDp3/nSJUvO1hsfK3 5bIftLWvowbZXT4fSEin8xmKQfqZfew4DdFFksWbBYMfycbOcW6ChGHUTVIXP0PeQA9K /n42DRLYAi72MnavK/i8LpKrJ4KXzVe+Et2WJS3ziccpzHpUHJhpnnjLEodjH1swG2wK 80FvZaDGWE0Xifykr4wxbeQbx3TqOpcXibmIeJzo4w2yWLRfBs1nQSngrCT/0327hM+G stibXdsFcyBMPxKIdte/OA8O7MIIS6WvY0DbUQ1DMAxdkEi4D/8BEN2q/9HBgqDhStDY Fw6g== X-Gm-Message-State: AOPr4FUyNuKs+oXN7jwXN7+aFSOX6xYcCWrHQQ5IDGW1nEkUgq0FHjIV8G2fIX5ypXxmpmZ3XMSjpK0pBQ0LjQ== MIME-Version: 1.0 X-Received: by 10.129.120.199 with SMTP id t190mr4283028ywc.45.1461758307875; Wed, 27 Apr 2016 04:58:27 -0700 (PDT) Sender: pierrick@webstart.fr Received: by 10.37.81.7 with HTTP; Wed, 27 Apr 2016 04:58:27 -0700 (PDT) In-Reply-To: <572069DD.9010708@zend.com> References: <571DD94B.3060604@zend.com> <571E63D0.8080800@gmail.com> <9c24f969-cb0e-cb46-a23c-6e06e7de7d79@gmail.com> <571E7C08.6010309@gmail.com> <571F1B95.9030203@zend.com> <572069DD.9010708@zend.com> Date: Wed, 27 Apr 2016 07:58:27 -0400 X-Google-Sender-Auth: GjFqEpgepNLKA_6L3lqGffqPqNc Message-ID: To: Dmitry Stogov Cc: Dominic Grostate , PHP internals Content-Type: multipart/alternative; boundary=94eb2c0b0854b072ce053176209a Subject: Re: [PHP-DEV] [RFC] PHP Attributes From: pierrick@adoy.net (Pierrick Charron) --94eb2c0b0854b072ce053176209a Content-Type: text/plain; charset=UTF-8 On 27 April 2016 at 03:27, Dmitry Stogov wrote: > > > On 04/27/2016 08:25 AM, Pierrick Charron wrote: > > Hi all, > > First of all thanks dmitry for your great work and for bringing the RFC > back to life. > > I think it would be great to allow users to define their own annotations > and give them some structure (what the annotation is made of). For example > let's say I apply an annotation to define that a property is a string with > a length. In the proposed RFC I will have something like this : > > class Foo { > <> > public string $bar; > } > > But how could i know for example that StringLength can take an extra > parameters I would have to read the code of the annotation framework see > how it parse, use it etc... But if I can define the structure (this is a > quickly invented pseudo syntax and I'm not proposing it) > > annotation MyAnnotation\StringLength { > private int $length; > private string $comment = "Default value"; > } > > With this definition I know that the Annotation take 2 parameters one int > and one string, that the comment has a default value and can be omitted > etc... > > Also what I dislike about using a simple array with no definition is that > you can't annotate an annotation since there is no definition. I know it > can look complex but think about the power you can add to the system. It > would help us solve some problems that could not be solved (or at least I > can't see any way of doing it) if you can't have a definition you can't > attach behaviour/metadata to it. > > Here are some problems we could solve (those are just examples) > > 1. Are annotations inhereted or not ? Some will say yes, some now but I > think they actually both make sense. For example we could imagine that if I > annotate a method of my interface as deprecated I want it to be inhereted > because all implementations are, but author annotation should not be > inherited because I'm not necessarily the author of the implementation. So > we could say that annotations are by default not inherited and we could > have an <> annotation > > <> > annotation deprecated { > } > > annotation author { > public string $name; > public string $mail; > } > > 2. Is a specific kind of annotation applicable to only one kind of > statement or multiple ? JIT don't make sense on a property... > > <> > annotation jit { > } > > 3. Current version of the RFC propose that we could either have AST or to > execute the AST but we could imagine to get both > > annotation assert { > <> > public ast\node $node; > public string $message; > } > > Again, this is just a couple of quick ideas, but this would make things > less magic/obscure with a definition and far more flexible. If we agree > that we want a definition we could work on how to create this definition > (we could use some stuff from the old Annotations RFC > > https://wiki.php.net/rfc/annotations?rev=1302087566) to update this one > with a new syntax or use interface as proposed in the first implementation > > class Deprecated implements Annotation { > } > > Maybe > > > didn't you think, that these annotation over-design made your RFC fail? > You maybe right, but the RFC was rejected 5 years ago and sometime people change their mind, that's why I want to get people thought about it as of today. If people still think the same that's fine with me, I'm just exposing for people new to it other possibilities. > > You can't create objects at compile-time, and should delay their creation > until Reflection*::getAttributes(). > Returning objects directly form Reflection*::getAttributes() doesn't > improve flexibility at all. > This would just increase the complexity of the patch... > I agree that this would increase the complexity of the patch but from time to time we have to do complex things :-) the Zend Engine is full of them and even if I agree that this should be avoided if possible it's sometime a necessity. But again this is just my opinion and I'll respect the community's decision. > > As I already said many times, all this extensions are possible to do in > few PHP lines on top of base functionality. > See "Doctrine use-case" at https://wiki.php.net/rfc/attributes#use_cases > > If you add these extensions directly into PHP implementation in C, you''ll > have to support them, and you'll always miss some needs for "last > use-case", but you won't able to change PHP behavior between major PHP > versions. > > Thanks. Dmitry. > > > > Pierrick > > > --94eb2c0b0854b072ce053176209a--