Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112107 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 40006 invoked from network); 23 Oct 2020 17:50:28 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 23 Oct 2020 17:50:28 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 456161804AA for ; Fri, 23 Oct 2020 10:08:08 -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,HTML_MESSAGE, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-mahalux.mvorisek.com (mail-mahalux.mvorisek.com [77.93.195.127]) (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 ; Fri, 23 Oct 2020 10:08:06 -0700 (PDT) Received: from 4d16232ded31 (10.228.0.190) by mail-mahalux.mvorisek.com (10.228.0.4) with Microsoft SMTP Server (TLS); Fri, 23 Oct 2020 19:08:03 +0200 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="=_946a2ac767cc43485bf1f9adc3218760" Date: Fri, 23 Oct 2020 19:08:02 +0200 To: internals@lists.php.net In-Reply-To: References: , Message-ID: X-Mailer: SAP NetWeaver 7.03 Subject: Re: [PHP-DEV] List of attributes From: vorismi3@fel.cvut.cz (=?UTF-8?Q?Michael_Vo=C5=99=C3=AD=C5=A1ek_-_=C4=8CVUT_FEL?=) --=_946a2ac767cc43485bf1f9adc3218760 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8; format=flowed Wdyt about dedicating "#" char for attributes? We can deprecate comments with "#" in 8.0 or 8.1 and in later version support attributes with "#" single character - without [] brackets, ie. support: #Attribute1 #Attribte2 public function x()... which will be equivalent to: #[ #Attribute1 #Attribte2 ] public function x()... Is there anything against excl. BC break of "#" comments? Who is for it? With kind regards / Mit freundlichen Grüßen / S přátelským pozdravem, Michael Voříšek On 23 Oct 2020 17:52, Theodore Brown wrote: > On Tue, Oct 20, 2020 at 10:13 AM Rowan Tommins wrote: > > On Mon, 19 Oct 2020 at 16:17, Theodore Brown wrote: > > In theory nested attributes could be supported in the same way with > the `#[]` syntax, but it's more verbose and I think less intuitive > (e.g. people may try to use the grouped syntax in this context, but > it wouldn't work). Also the combination of brackets delineating both > arrays and attributes reduces readability: > > #[Assert\All([ > #[Assert\Email], > #[Assert\NotBlank], > #[Assert\Length(max: 100)] > ])] > > I think you're presupposing how a feature would work that hasn't > even been specced out yet. On the face of it, it would seem logical > and achievable for the above to be equivalent to this: > > #[Assert\All( > #[ > Assert\Email, > Assert\NotBlank, > Assert\Length(max: 100) > ] > )] > > i.e. for a list of grouped attributes in nested context to be > equivalent to an array of nested attributes. Hi Rowan, The problem with this is that it results in inconsistent semantics, where the number of items in an attribute group results in a different type of value being passed. I.e. if you remove two of the three attributes from the list, suddenly the code will break since the `Assert\All` attribute is no longer being passed an array. // error when Assert\All is instantiated since it's no longer being // passed an array of attributes: #[Assert\All( #[ Assert\Email, ] )] So when removing nested attributes from a list such that there's only one left in the list, you'd have to remember to additionally wrap the attribute group in array brackets: #[Assert\All( [#[ Assert\Email, ]] )] And of course when you want to add additional attributes to a group that originally had only one attribute, you'd have to remember to remove the extra array brackets. Generally speaking, having the number of items in a list change the type of the list is a recipe for confusion and unexpected errors. So I think the only sane approach is to ban using the grouped syntax in combination with nested attributes. Unfortunately, no one thought through these issues when proposing to change the shorter attribute syntax away from @@ and add the grouped syntax, and now it seems like we're stuck with a syntax that is unnecessarily complex and confusing to use for nested attributes. > Unless nested attributes were limited to being direct arguments to > another attribute, the *semantics* of nested attributes inside > arrays would have to be defined anyway (e.g. how they would look in > reflection, whether they would be recursively instantiated by > newInstance(), etc). Yes, the exact semantics of nested attributes need to be defined, but this is a completely separate topic from the grouped syntax issue described above. As a user I would expect nested attributes to be reflected the same as any other attribute (i.e. as a `ReflectionAttribute` instance). Calling `getArguments` on a parent attribute would return an array with `ReflectionAttribute` objects for any nested attribute passed as a direct argument or array value. On first thought I think it makes sense to recursively instantiate nested attributes when calling `newInstance` on a parent attribute. This would allow attribute class constructors to specify the type for each attribute argument. But again, this is a separate discussion from the issue of nested attribute syntax. Kind regards, Theodore -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php --=_946a2ac767cc43485bf1f9adc3218760--