Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111945 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 68466 invoked from network); 28 Sep 2020 13:46:53 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 Sep 2020 13:46:53 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 385A51804B7 for ; Mon, 28 Sep 2020 05:58: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=-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_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (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, 28 Sep 2020 05:58:16 -0700 (PDT) Received: by mail-ej1-f52.google.com with SMTP id p9so8353329ejf.6 for ; Mon, 28 Sep 2020 05:58:16 -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=TDnmm6ipLE/xou0V4T+8DvEGTZ2Tk3xFAXkbc3b6v5U=; b=DFPIU1pBSU7+hC87eEbtI6kL19CSUa4GCCh0c6tzE96At/LvS55N5+wjiqtbP7k61X ptzHfOwf52VrcygLzzGFthIOzS8f4rO21yteLxWap2O/sNdOmCGTOONk3Uh0EMBFCXxo 3UJPT+Dv/G4n2xii0qPrBTY1fL4LyBev5QSGRI/81zSKRK/UX829YvYJsr0h6XdmPyPN qqYAECVfuqxbycxRJqx2gUG9M5g24W5WVeTthm9UNnrfDUXSzpEjO9rKdCL9+yE8XIDI eidQmkj+IT/Qv835nrp8xA9SbU1L13ak0gmaMJdkJ9aN29iDq5Ii4Oaj4LHLwgSBFJ0V Dlhg== 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=TDnmm6ipLE/xou0V4T+8DvEGTZ2Tk3xFAXkbc3b6v5U=; b=Tf3iLNnnbJeA9ecYxrJzdfmtAMB8olFeSnqwxW69Pd85jaRtcxh5/qoOPLO0CvE/Dr dqdOB1wwzxdQGDyyuOxUdToNsMjywiXAwchA21At448AQ9d2dO8D3R3tU7duP0H992Zb 9F6cSzgxMCtiUnoXE8TeCiFY6xMHpY5EM7LMW6BqLq9+3IFBJG3lGjzeXZX5MeDPGl48 OU67Un1QttfIZedYq6aLR03anXWN7jLhFHwWuk13TASNFDMl8VTwYPk6xHNMMnwzSvif jO4AFUTF3bOhD2hbHXU6QD7EMKMTxL1hLYX+Dwx+BLAROVVq5J3SreSvraXCJrCWEKpN SZsQ== X-Gm-Message-State: AOAM532y2RD1TKbOP54DGSK2zUA/cIN0fsoHEIHQIEmyeyx1/h+aI8aO 1M5wbOXOnyob56sgWqtAa8oBCHVxEi8o0di4OIOuxQQ3SJeZKQ== X-Google-Smtp-Source: ABdhPJz7bGiRECCD61KJLiDLyoPaaRVb0TdHcBmDSPHeWMeEVKuOXtdH7On9f3DaQtwFz+7/0MvaG9+3V2fDqU5j37Y= X-Received: by 2002:a17:906:4805:: with SMTP id w5mr1576860ejq.313.1601297895173; Mon, 28 Sep 2020 05:58:15 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 28 Sep 2020 14:58:03 +0200 Message-ID: To: Nikita Popov Cc: Benjamin Eberlei , PHP Internals List Content-Type: multipart/alternative; boundary="00000000000038c21505b05f383c" Subject: Re: [PHP-DEV] List of attributes From: nicolas.grekas@gmail.com (Nicolas Grekas) --00000000000038c21505b05f383c Content-Type: text/plain; charset="UTF-8" > Hi Benjamin, hi everyone >> >> 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)]. > That's what I've read in previous discussions and in other replies in this thread. This would break the possibility to read annotations without failing hard when a class is missing. I would much prefer a solution that preserves this capability (which is the reason why we have ReflectionAttribute::newInstance(): unless this one is called, no autoloading happens. To me, this means that "new Foo()" nested in an attribute can't be a solution. Neither should we be able to nest PHP constants there btw. Since we borrowed the syntax to Rust, here is the syntax they use: > #[validate(length(min = 1), custom = "validate_unique_username")] I think this would fit quite nicely for us too, by turning eg length into an instance of ReflectionAttribute. Note that a use case for nested attributes is discussed in https://github.com/symfony/symfony/pull/38309, to replace things like: /** @Assert\All([ @Assert\Email, @Assert\NotBlank, @Assert\Length(max=100) ]) */ We can work around of course, and we will for 8.0, but it would be nice to have a plan forward because similar use cases (grouping attributes in a wrapper attribute) are going to be pretty common IMHO. But we're getting a bit of topic. I'm fine keeping things as is for 8.0. I just wanted to raise a point about the syntax for list of attributes but it didn't get traction apparently. Cheers, Nicolas --00000000000038c21505b05f383c--