Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111958 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 85595 invoked from network); 29 Sep 2020 14:33:57 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Sep 2020 14:33:57 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0F8711804AA for ; Tue, 29 Sep 2020 06:45:37 -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=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 29 Sep 2020 06:45:36 -0700 (PDT) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 9A5965C01BB for ; Tue, 29 Sep 2020 09:45:35 -0400 (EDT) Received: from imap26 ([10.202.2.76]) by compute7.internal (MEProxy); Tue, 29 Sep 2020 09:45:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=90xJ7EygUMK5TxTUw+swUg8ig4GHE/q0QAFI7r4iz p0=; b=fXIjrXXa8w2B7EW/2iq8ERhKuntxbNrgrl+YbGdxQ/68kl8CdS7hGTk3O ijkZqcOnI3GdVc76WHz4DTrW2aKv+OM30aPq0s79+i9lzik3/KItS9+FQi1qfRzy NPr4jzUykvMOXmOxZyB5D3cYRXMDMNLNWAv2anYeEzCmumni8HNQD7PYxZJEBbLr pIl2Nedo587EkFCz+bNx08vHa0q42UH2I3xru5rBFJ4dAx9Glm8EcKbnV3xzl0Dm /yStldXDZH0yUQfWN7jgKq+v4UbWZj6jduuiAenLEYDxBpXsEMTz1NbpvXE8wrGS 3tQiXXVipKtzTJQ1uTbOVyltSlTbg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrvdekgdeilecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvufgtgfesthhqredtreerjeenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpeffffffjeffudfggeevvdeitdetvdfgjefffeffjeel feejteevheeghffhvdfgleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id F0B14142016B; Tue, 29 Sep 2020 09:45:34 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.3.0-355-g3ece53b-fm-20200922.004-g3ece53b9 Mime-Version: 1.0 Message-ID: In-Reply-To: References: Date: Tue, 29 Sep 2020 08:45:12 -0500 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Re: Attributes and constructor property promotion From: larry@garfieldtech.com ("Larry Garfield") On Mon, Sep 28, 2020, at 12:06 PM, Benjamin Eberlei wrote: > On Mon, Sep 28, 2020 at 4:35 PM Benjamin Morel > wrote: >=20 > > On Mon, 28 Sep 2020 at 15:17, Nicolas Grekas > > wrote: > > > >> I assume the 80% case is properties, because attributes did not hav= e > >>> docblock annotations yet, that means this use-case isn't even poss= ible at > >>> the moment. Yet annotations on properties are widespread (Doctrine= ORM, > >>> symfony validator, ...). > >>> > >> > >> I'm 100% with Benjamin here, this is what will be the most useful t= o me > >> also. > >> > > > > To be clear, I don't have a strong opinion against yours, I'm just > > pointing out the fact that even though it might be useful, it might = also be > > confusing and create yet another WTF moment in PHP for developers. S= ure, it > > might make more sense to apply to the property. Sure, so far annotat= ions > > weren't possible on parameters. But is that obvious to the average > > developer writing the attribute? A few years down the road, DI conta= iners > > may have broad support for annotating parameters for injection. Will= it > > still be obvious then that an attribute on a promoted property appli= es to > > the property only? > > > > I do agree that applying the attribute to both the property and the > > parameter will probably never be useful, though. So, throwing an exc= eption > > and forcing the de-sugaring feels like the most sensible thing to do= for me > > in this case! > > >=20 > I haven't checked if this is possible in the code doing the "desugerin= g", > but what if we had an attribute on the constructor that could specify = where > the attributes should apply to? >=20 > #[AttributePromotion(Attribute::TARGET_PROPERTY)] > public function __construct(#[Foo] public string $bar) {} >=20 > Then we could apply it to both by default, which is what is probably t= he > expected approach, and users could change it to apply only to properti= es, > which is what is the use-case that makes most sense. >=20 > > > > =E2=80=94 Benjamin From a user experience POV, I'd almost expect the opposite. If I mark the attribute as being for properties, it gets applied to the = property. If I mark the attribute as being for parameters, it gets applied to the = parameter. If I mark it for both, or don't restrict it at all, it applies to both. That may not be how the logic is currently implemented but that's what a= s a user I'd find least-surprising. --Larry Garfield