Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108931 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 10208 invoked from network); 10 Mar 2020 01:08:33 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 10 Mar 2020 01:08:33 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D413C180088 for ; Mon, 9 Mar 2020 16:29:17 -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-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 ; Mon, 9 Mar 2020 16:29:16 -0700 (PDT) Received: by mail-wm1-f53.google.com with SMTP id n2so54432wmc.3 for ; Mon, 09 Mar 2020 16:29:16 -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=UvxRUd2acwkxJOb6VJlm54Anz1WjNFXx+FUgqT7BYv4=; b=sl0ie8tK32Hpy6mla4+ArUyU7EJiNk5eTJJmR1xWYx84XuqdfD75PWEYNq+hYtSD7d T3Osw0LtM9teGlzT/VT7pP4Zyt0DjjhuI8goyz7zi2dIgZ1idLLYpDyyLvzuRA7+E5uy o5OJ5H/2qpk0BMLIT1pMe0vb12CX1YOAHaGfMmoKMnUiz3kJ+hdPo9UbnDfi6MwPQyzL vDT7J9gTJ2yHvI/8KwGw5jp+Yo/wsz9/10Y2x+KJf8NH/GklzCPynLihbIvlfV0nU7tY 2qrwHGM4BQf0ZFlxMI9gdjh06UByt13ZOzsC8xyh3jJrLB6og6slmOuhDEkjsBSsBjLC hGOg== 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=UvxRUd2acwkxJOb6VJlm54Anz1WjNFXx+FUgqT7BYv4=; b=JyGP3azHFBFpEMqa3cWYczL6en+vUHPTR2H3dNvU3ftu+WwomFkC0JV9leS8+WXHSX 2Ny3uM48yRwZxyzyzGxZW1+F/N8tmhNttNlrPVnfTNK81cW8gUaM0RnDHooxGEDMLGAW M78b7BvvKCa0rTMG5ovwahRhKcamW1Ac9kTF/5Ypq4hHZq8MJ3D6UCCs6oJLErLV0oxR +3CFlAjxDl6B2s2dJmnnWxyK6N64XifRk8q3kSEblbJAWZeCmlf9B1lXI/ySeZS+CIU2 EfAQ2NRmv39lNBVeUdctoVCzOmc0tr1+xm9kR+bGc5rxygQVX0wZnqhY+mtC6N9WIShZ B44g== X-Gm-Message-State: ANhLgQ0ILX747Ck53vrVWj6RhCn0FTFC7TJZGkRdK62CPnfvjznpZzSL D8gtSPr1ZOZdTjhe3l7IfiKZWUKjpSGBr1J24B3f4c2lgIQ= X-Google-Smtp-Source: ADFU+vt+l1G47Cf7YycezaaG77HVNw3ZC4Ih4QL7oG8SC7vmeH0tHKKL2P5rHBHCxwrgxZ424uL5IMwIi4IE/uxIPB4= X-Received: by 2002:a1c:ed04:: with SMTP id l4mr1474044wmh.36.1583796554165; Mon, 09 Mar 2020 16:29:14 -0700 (PDT) MIME-Version: 1.0 References: <2461944e-bc66-4941-aef4-ed07aefa3858@www.fastmail.com> In-Reply-To: <2461944e-bc66-4941-aef4-ed07aefa3858@www.fastmail.com> Date: Tue, 10 Mar 2020 00:29:02 +0100 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="00000000000002047705a0745f0b" Subject: Re: [PHP-DEV] [RFC] Attributes v2 From: kontakt@beberlei.de (Benjamin Eberlei) --00000000000002047705a0745f0b Content-Type: text/plain; charset="UTF-8" On Mon, Mar 9, 2020 at 11:03 PM Larry Garfield wrote: > On Mon, Mar 9, 2020, at 9:42 AM, Benjamin Eberlei wrote: > > Hi all, > > > > I want to resurrect Dmitrys Attributes RFC that was rejected for 7.1 in > > 2016 with a few changes, incorporating feedback from the mailing list > back > > then and from talking to previous no voters. > > > > The RFC is at https://wiki.php.net/rfc/attributes_v2 > > > > A working patch is at https://github.com/beberlei/php-src/pull/2 though > > work around the details is still necessary. > > > > The RFC contains a section with common criticism and objections to > > attributes, and I hope to have collected and responded to a good amount > > already from previous discussions. > > > > There is also a fair amount of implementation detail still up for debate, > > which is noted in "Open Issues". I have pre-committed to one approach, > but > > listed alternatives there. On these issues I am looking for your > feedback. > > > > greetings > > Benjamin > > I am very excited to see this back, and overall I like the approach! > > Thoughts in no special order: > > * It's not entirely clear, but the values in an argument-carrying > attribute are passed to its constructor variadically? Viz: > > <> > function stuff() {} > > class Foo implements Attribute { > public function __construct(int $first, int $second, int $third) { ... } > } > > Yes? (And then if you wanted to capture them all you could use a ...$args > parameter in the constructor.) > > * It looks like the only way to support named parameters would be to pass > an associative array and decompose it yourself. That's... better than > nothing I guess but also we're back to the same lack of self-documentation > we always lament. Is there any opportunity to do named parameters in some > other way? > Improvements here are contingent on any named parameters support, which could > > * Is it possible to inline a sub-object, or no? Viz, is this legal, or > would we want it to be legal (I'm assuming it's not at the moment): > > <> > function stuff() {} > No thats not possible, because the constant expression syntax doesn't allow this. See Tysons proposal lately to allow function calls in constant expressions: https://externals.io/message/108630 > > * I *really* dig how you can filter annotations to just those that match a > certain parent class/interface. That was one of the nicer parts of PSR-14 > so I'm really glad to see the same "make the type system earn its keep" > approach here. It encourages packages to interface-tag their annotations > so they can easily grab "just theirs". +1 > > * The "more complex Doctrine ORM use-case" example includes inlining > multiple annotations together: <> > . Is that just an oops since that possibility was only just added to the > Open Issues? > > Ah this is a mistake, I removed that use-case and settled on a single syntax. > > Regarding open issues: > > * If constant expressions are easy enough to support, I don't see a reason > not to support them. > > * I'm torn on the marker interface. On the one hand, a marker interface > would make it easier to audit a package for all of its attributes; just > grep for "implements Attribute". I'm sad that we didn't get a marker > interface in PSR-14 for that reason. On the other, if it doesn't do > anything except be a marker then it doesn't really offer anything else; and > it also potentially makes it harder to add some special casing of > attributes in the future, say to offer "if you want this extra attribute > behavior, use this interface/base class/whatever." I could go either way > here. > > * Letting attributes say where they're legal would be a good case for such > a more-than-marker interface. > I am not sure. This is something PHP would validate at Reflection::getAttribute() time, at which time it is also easy to validate for userland implementations. > > * The aforementioned example of specifying where an attribute is legal > implies that attribute classes can themselves have attributes. True? If > so, that should be made explicit elsewhere in the RFC. I'm not against > attribute-ception, but that should be explicit. > > Attributes are just PHP classes, so they can indeed have their own attributes. So a userland library building on top of attributes, could call getAttributes() then validate that each attribute returned has itself an attribute that "marks the target": <> class Entity { } > I think my only significant pushback at the moment is that attributes here > suffer from the same redundancy problem as any other value object. To wit: > > class Owner implements Attribute { > > public readonly string $name; > > public readonly string $title; > > public readonly int $age; > > public function __construct(string $name, string $title, int $age) { > $this->name = $name; > $this->title = $title; > $this->age = $age; > } > } > > <> > function stuff() {} > > That necessitates the same quadrupal-repetition that other constructors > have. Since I anticipate the 99% use case to be exactly that, the pain of > that redundancy (and the mandatory unnamed order) will be felt rather > dramatically here and thus hurts ergonomics. Is there no way that we > address that? > This is not something to fix for this RFC, but any solution here and attributes can benefit from it as they are just PHP classes. > > I realize the answer may be "no more than any other class, they all suck > equally". Are we at least certain then that if we can solve that in the > future for classes generally that it will automatically work here? (Eg, if > new Owner({name: 'Larry', 'age' => 99, 'title' => 'Manager'}); became a > legal shorthand for the above, it would automatically work for annotations > as well.) > > Overall nice work, and I hope to get to use it. > > > --Larry Garfield > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --00000000000002047705a0745f0b--