Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112078 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 84900 invoked from network); 19 Oct 2020 20:00:14 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 19 Oct 2020 20:00:14 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 257E01804B5 for ; Mon, 19 Oct 2020 12:16:56 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (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, 19 Oct 2020 12:16:52 -0700 (PDT) Received: by mail-lf1-f45.google.com with SMTP id z2so953763lfr.1 for ; Mon, 19 Oct 2020 12:16:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=75Rdmd7ES8oUee7NNxnuSJ6bpmpLMo7KBvH5jQHBbEk=; b=gAz09t77rCOzjchl+x6OqZkImWdd/ZfgOOxS/l7yKoPU/4Ayq1wmOd+iTiARjey/Jp jHBezKDxmHYwy7SOYjNVpYHDaJZW6mRJXd+5gvxG+Jyp3m3QxdvbTP6A+LbI9qsVjzH1 VTfrmjh9wnDyUoemQQWuRDAI6VoypN8d0tEbNiLNXCy6/1hfvVzrqMlmmkVQdlaM4zxI oEGbqN0K06CFVPrWjDG6ead1FIXPI03Ujyv/pZO6PQkF9I1lfl6HTwmUXHEAq0XVhI5q 2iq4F7+TeFTMFs2/YR+FLRsjXSuIOPDz1/LdNM7bwhpI3fwaDEzKkjRll49aEwdwIcuH 4YYw== 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=75Rdmd7ES8oUee7NNxnuSJ6bpmpLMo7KBvH5jQHBbEk=; b=O3XY+Iq5aC6fU8nejsWyE57Ge7WvQC9V+Fvxn4GhU5izvYR2eHFMQ4QiL6lj072EVT YH8PvKIxjJQ8/7OgacFRwK5r6WWNTa+qbrlxlrO6Mf1fosQ8ywipUlqU/jRlYfQUAYDz T5mFz4U4E7noLyGAkQ98/plNVD8xZktn6LBSyGcjAG/CstvPqBXQPvNamx5Ac3iZg8oX bsM82+ExefMtAlXUNNTS9VhJpMXljra30ZALYfTMxRqXCUA4OoOzIgVQPLYd8cCungVS /QAB4iWvPPkUiBXrz5JfwWlHl6TrOXbwXFKMKV4gliukhRiqoysuuMDAHxgRQM8gAVux +K2A== X-Gm-Message-State: AOAM5326+fN00WESmq1pBaH2g6juRlAGK7sDNwhQidiKrsi5pViGBvt+ nG3US5ZYB1fmqfmS9pru/IGM+UWMU21oPUsEMxQ= X-Google-Smtp-Source: ABdhPJyNoi2Dko+Ljy3d5qNbmJW3Ow056eQIeDdth6SkaWIShCgV3lLH7uGCenR0s7KI70+kiYuPvYimm6LblMpTkiA= X-Received: by 2002:ac2:4e90:: with SMTP id o16mr399657lfr.251.1603135010718; Mon, 19 Oct 2020 12:16:50 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 19 Oct 2020 22:16:37 +0300 Message-ID: To: Theodore Brown Cc: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000d7468b05b20af486" Subject: Re: [PHP-DEV] List of attributes From: benas.molis.iml@gmail.com (Benas IML) --000000000000d7468b05b20af486 Content-Type: text/plain; charset="UTF-8" On Mon, Oct 19, 2020, 6:17 PM Theodore Brown wrote: > On Mon, Oct 5, 2020 at 9:24 AM Nicolas Grekas > wrote: > > >> I'm wondering if the syntax that allows for several attributes is > >> really future-proof when considering nested attributes: > >> > >> > >> *1.* > >> #[foo] > >> #[bar] > >> > >> VS > >> > >> *2.* > >> #[foo, bar] > >> > >> Add nested attributes to the mix, here are two possible ways: > >> > >> *A.* > >> #[foo( > >> #[bar] > >> )] > >> > >> or > >> > >> > >> *B.* > >> #[foo( > >> bar > >> )] > >> > >> The A. syntax is consistent with the 1. list. I feel like syntax > >> B is not desired and could be confusing from a grammar pov. > >> BUT in syntax 2., we allow an attribute to be unprefixed (bar), > >> so that syntax B is consistent with 2. > >> > >> Shouldn't we remove syntax 2. in 8.0 and consider it again when nested > >> attributes are introduced? > >> > >> I voted yes for syntax 2. when the attributes were using << >>. I would > >> vote NO now with the new syntax. > >> > >> Nicolas > > > > As far as my understanding goes, if we introduce "nested" attributes, it > > will be in the form of relaxing constraints on constant expressions, i.e. > > by allowing you to write #[Attr(new NestedAttr)]. > > > > Nikita > > Back when the original `<<>>` attribute syntax was being implemented, > there was an attempt to do just this. But it turned out to be very > difficult to implement, and it was ultimately given up on since it > required significant changes to const expressions. Earlier this year > there was also a poll to gauge interest in supporting function calls > in constant expressions, but most voters opposed it. [1] > > Even if a proposal for relaxing constraints on constant expressions > gains enough support, it's not clear this is the ideal path forward > for nested attributes, since as Nicolas pointed out this wouldn't > have the same lazy-loading semantics as existing attributes. > > Straightforward support for nested attributes was one of my main > motivations for proposing the `@@` syntax in the Shorter Attribute > Syntax RFC, [2] and I had hoped to collaborate on a follow-up RFC to > support nested attributes with the AT-AT syntax. This would allow > existing nested docblock annotations such as Nicolas's example to > translate intuitively to native attributes: > > @@Assert\All([ > @@Assert\Email, > @@Assert\NotBlank, > @@Assert\Length(max: 100) > ]) > > This would also preserve the lazy-loading feature where these > attribute classes aren't loaded until code calls `newInstance` > on one of the `ReflectionAttribute` objects. > > But then the Shorter Attribute Syntax Change RFC [3] came along and > derailed this plan... > > 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: > Welp, both variants seem to be readable. > #[Assert\All([ > #[Assert\Email], > #[Assert\NotBlank], > #[Assert\Length(max: 100)] > ])] > > But at this point I assume this is the most viable path forward for > nested attributes (barring another syntax re-vote and delay of PHP 8). > Are you actually kidding me? 4th revote? Please no. I know Derick and Benjamin have stated they aren't in favor of nested > attributes and didn't put any thought into the syntax for them, but I > feel this is unfortunate since nested attributes are an established > pattern with legitimate use cases in existing libraries. > > Best regards, > Theodore Best regards, Benas > > [1]: https://wiki.php.net/rfc/calls_in_constant_expressions_poll > [2]: https://wiki.php.net/rfc/shorter_attribute_syntax > [3]: https://wiki.php.net/rfc/shorter_attribute_syntax_change > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > --000000000000d7468b05b20af486--