Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110395 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 44806 invoked from network); 5 Jun 2020 23:19:17 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 Jun 2020 23:19:17 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 862861804F6 for ; Fri, 5 Jun 2020 15:02:00 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 5 Jun 2020 15:01:59 -0700 (PDT) Received: by mail-wm1-f47.google.com with SMTP id c71so9668973wmd.5 for ; Fri, 05 Jun 2020 15:01:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=beberlei-de.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=OM+ZLt8TnPuvut55VkHtFrnwABjS+9TJ/7LseWCPxkE=; b=ngh+GwkXJFzHwVEIPhUhdjLO/nmuFMTzkrh/mQLDUdq3h1qTE03ctr/lmXTr/0ArJ8 ko7g6hizYs816DS9lw/9HODI7i3vs5O2+zzOHGOYp0u4pfgNunaMGqldpI8skwpUdP4G Pov2qxTzt35glTxr1Et4mVxTKkbukQEaJoy5QoGHjlArRx6LTtG7OPvZokOfNNTAuf/M ENe074iCcTAGGIiFmyKNDEnPBlKrnNOfQUTupynRzUw+ddWQR4t959PmaxbfOzwPvccu SvF9tjVHOx9jgcERKBYkUk12W+RF2+12tzcdsPU+do70EIYetgT1nOdcRap8qTniRw1g oD5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=OM+ZLt8TnPuvut55VkHtFrnwABjS+9TJ/7LseWCPxkE=; b=S53tlnFzSEos90vsgpuH/2uDFw66HXHow7woAQ0UN1uQ5yYH6YTHm9t7fgZqwQ6zGY 8qtoTXV8e1+52iHJkBH9nVFosjItuqYzpi2impJQaPSDUpYplnxzErqEtzNpsbnHNmpw OhX01KPg8DKPjnAN41uJITmzaSatCgqLWL4nzvNvPMVYQ58LHAXTOJGtP5QLU+kQ66XL 7Qc62J8BBgwv53wEUvByp31Cw3LTbRfxo30jf/muEY0NCfHd1/Qsr2tP/GWXeTH/0ykT obc7ncsimvhUjZnCjJgVB+CPvc2H5QvR2fNv6NJ3IrwU+vce4X3UUsbOPEH2nhFqWHyj u1SA== X-Gm-Message-State: AOAM5328bNps3ZDNAPt/7qg3e2a2I1VJQgLaxBm1ot3WrMWyFrf04t21 WNE851C98/QFEaaJPUs44t1h1iLgRmW/XNIpRJONWg== X-Google-Smtp-Source: ABdhPJyWhahaxR5/Jm8ES7SN64ajIJDQNJkoSH5sI8ROgkNT7WBxUsQ+ZODNFdhdrN28fTMfw5F+NdejNBKaTcBQ1eQ= X-Received: by 2002:a1c:810a:: with SMTP id c10mr4568808wmd.107.1591394517746; Fri, 05 Jun 2020 15:01:57 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 6 Jun 2020 00:01:46 +0200 Message-ID: To: "guilhermeblanco@gmail.com" Cc: Benas IML , PHP Internals Content-Type: multipart/alternative; boundary="000000000000ed98cf05a75d684e" Subject: Re: [PHP-DEV] Re: [RFC] Amendments to Attributes From: kontakt@beberlei.de (Benjamin Eberlei) --000000000000ed98cf05a75d684e Content-Type: text/plain; charset="UTF-8" On Fri, Jun 5, 2020 at 5:58 AM guilhermeblanco@gmail.com < guilhermeblanco@gmail.com> wrote: > Hi Benjamin, > > Overall, all these amendments are good in my opinion, but I'd like to > challenge a few things: > > 1- On item 3, the acceptable targets would be: class, function, > method, property, class constant, parameter or all. > If possible, I'd like to ask if it's possible to expand this list and > also allow attribute and constructor. > I think this is too specific to be valuable in the language, and it could always be validated at the attribute reading level in userland. One thing i was thinking now, what if attributes could be "Reflection declaration aware", example: interface ReflectorAwareAttribute { public function setReflector(Reflector $reflector); } class MyAttribute implements ReflectorAwareAttribute { public function setReflector(Reflector $reflector) { } } ReflectionAttribute::newInstance() would check for this interface and call setReflector if present. > > 2- Also on item 3, the validation of PhpAttribute targets, it feels > more natural to have this as an array instead of a bitwise or > operator. > Have you evaluated the performance penalty to judge your decision of > bitwise vs array? > I feel this is subjective, PHP APIs generally use bitmasks for this kind of differentiation and not an array of strings. An array of strings would have the problem of the case with one target only: ["class"], which soon would raise requests for a string "class" only, where a union type is probably more "complex" than a bitmask. > > 3- Repeatability should be on its own PhpAttribute. It would not block > the expansion of the repeatability in future efforts. > One possibility could be group repeated attributes as another > PhpAttribute. Example: Multiple <> be folded into a > <>. > This code: > > <> > <> > > Would be equivalent to (sorry if syntax is not 100% correct): > > < <>, > <> > ])>> > > Considering: > > <> > <> > class Schedule { public string $cron; /* ... */ } > > <> > class Schedules { public array value = []; // Holds an array of Schedule } > Without knowing at all how and if nested attributes get supported in the future I feel this introduces a lot of complexity that is unnecessary. If nested attributes are added at some point the validation could be done in the container attributes constructor. Taking your example: <> class Schedules { public function __construct(array $schedules) { foreach ($schedules as $schedule) { $this->addSchedule($schedule); } } private function addSchedule(Schedule $schedule) {} } Any kind of language support for typed arrays would obviously simplify this even more. > 4- Now you might have recall about my initial thoughts on this > subject, but inheritance is something that would be very interesting > to see as part of this amendment. > If we introduce something like <> to the > Attribute definition, we could then mark the Attribute to be inherited > to subclasses of attributed class, while keeping the default to do not > inherit anything (like we have today). > An equivalent of Java Annotations @Inherited is not easily possible, so we omitted it for now. The reason is that the compile step does not validate attributes (unless they are internal engine attributes, that can only be provided by extensions). So it doesn't know at that point if the declared attribute exists and what inherit rules it might hvae defined. One solution could be to add a new flag to ::getAttributes($name, $flags = ReflectionAttribute::INCLUDE_INHERITED) that performs the gathering of inherited attributes, however that will have to trigger autoloading. The complexity and the rare use case for me speaks against adding it at the moment. > > Cheers, > > On Thu, Jun 4, 2020 at 1:49 PM Benjamin Eberlei > wrote: > > > > On Thu, Jun 4, 2020 at 12:54 PM Benas IML > wrote: > > > > > Thank you for the update! Given that there is still an open issue, is > the > > > RFC proposing flags or a separate `<>` attribute? > > > > > > > Good point, we came to the conclusion to simplify. Should attributes be > in > > the global namespace, then we shouldn't arbitrarily add more, so it will > be > > a flag. > > At that point, because you rarely declare new flags we decided to merge > > target and flags and only have one flag. You could do the following: > > > > <> > > > > > > > > Best regards, > > > Benas > > > > > > On Thu, Jun 4, 2020, 12:29 PM Benjamin Eberlei > > > wrote: > > > > > >> I have changed back the rename from namespacing to > Attributes\Attribute to > > >> using just Attribute after a few discussions off list. The reasoning > is > > >> that it becomes more clear that a majority of core contributors > strongly > > >> prefers using the global namespace as the PHP namespace and opening up > > >> this > > >> point again makes no sense. So the state of the RFC is again what it > was > > >> when I originally posted it with renaming PhpAttribute to Attribute. > > >> > > >> Unless there is some new significant feedback I am going to open up > this > > >> RFC for voting on Monday next week. > > >> > > >> On Wed, May 20, 2020 at 7:07 PM Benjamin Eberlei > > > >> wrote: > > >> > > >> > Hi everyone, > > >> > > > >> > the Attributes RFC was rather large already, so a few things were > left > > >> > open or discussions during the vote have made us rethink a things. > > >> > > > >> > https://wiki.php.net/rfc/attribute_amendments > > >> > > > >> > These points are handled by the Amendments RFC to Attributes: > > >> > > > >> > 1. Proposing to add a grouped syntax < > > >> > 2. Rename PhpAttribute to Attribute in global namespace > (independent of > > >> > the namespace RFC) > > >> > 3. Add validation of attribute class targets, which internal > attributes > > >> > can do, but userland can't > > >> > 4. Specification if an attribute is repeatable or not on the same > > >> > declaration and fail otherwise. > > >> > > > >> > Each of them is a rather small issue, so I hope its ok to aggregate > all > > >> > four of them in a single RFC. Please let me know if it's not. > > >> > > > >> > greetings > > >> > Benjamin > > >> > > > >> > > > > > > > -- > Guilherme Blanco > SVP Technology at Statflo Inc. > Mobile: +1 647 232 5599 > --000000000000ed98cf05a75d684e--