Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111952 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 45953 invoked from network); 29 Sep 2020 08:23:51 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Sep 2020 08:23:51 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 60B721804B7 for ; Tue, 29 Sep 2020 00:35:24 -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-Virus: No X-Envelope-From: Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (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 ; Tue, 29 Sep 2020 00:35:23 -0700 (PDT) Received: by mail-wr1-f48.google.com with SMTP id j2so4137021wrx.7 for ; Tue, 29 Sep 2020 00:35:23 -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=P0hoszdQs0cc+LOj6KsO6yl9MVu+Qj+T1c4XB7XEr7s=; b=A5BWt/Oj0EvzVAVPCkrkqHEXmjDDUQtVTAkUueFe3otjMEl+U5HP34HFoW9+tSn7zp 8pGm3YHIx7k1qey3RZVW7EyDy1GZhGTXKUYtUs00JUsI6n8dnLKDXObSPZHvDWfT85dX AuVWQ4sYbKcwXSWX1XeSUs4KmCwexq6LCo2PkDD1rNaRMc6AODOT9nzZUNwzabxjydq4 JztGj5Sek/7JL1ksv5GGrUFmTmV1CQSd84wog3kdQfj7KjWBnxzBLzVgPuy0lMglGO4I YQOimKRQ7tN7r2cdXxGQ7Qj4qDeaP25eo1gUhm7w5AUPcx03mBcfz5bTW+O2MeiqC8Wi L+Mw== 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=P0hoszdQs0cc+LOj6KsO6yl9MVu+Qj+T1c4XB7XEr7s=; b=dqoLDlQoFcclykqS0g4OdXiCPmqzkR8dkMqhEvR2NW2Oy/MVAWoFheON0Vh+1flGHt gNiwSghLz35aEYfS/m6808fSttHzhh6TgJXJd4ZQvB7AotW7nCEMWzr3JLBiKp5rc3p5 bCyABZKqzisTlfLKMiFcOPCCBjUEahPgL+Eedge+H9sFrdLGp1T0UsdmLo5EBiH0vj6X 5zPz3ImWq+X+7vhcrbVKR2KhZSF4m9NdmJVgFj5ncqcHu9xfXtvohIFep9w4f0zuoBI4 fUnVRKv41drMjKGU7XyyvgvjrSOAGkWHIVoyh7IBfYOj/uBHzmZ79DK+zejzaUCxpNLH nUpA== X-Gm-Message-State: AOAM533T/O2ytngs8O18ycc72TsbYWVojap8Zt1NFexWrcUbFLwxrsfP TdruGCL62liYMgzIo8R58WwdyTBOe1tv2z0S+su0aQ== X-Google-Smtp-Source: ABdhPJzq8E6sCZ5P97DZfQ4/2VdjGFK5tm7AXjuKxpdusMfb12K1kyDOR8BdTiW0KNRwSIbLjiItcABkQB6wQtfdOKc= X-Received: by 2002:adf:e488:: with SMTP id i8mr2797560wrm.116.1601364919474; Tue, 29 Sep 2020 00:35:19 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 29 Sep 2020 09:35:08 +0200 Message-ID: To: Nicolas Grekas Cc: Nikita Popov , PHP Internals List Content-Type: multipart/alternative; boundary="0000000000002e73f405b06ed349" Subject: Re: [PHP-DEV] List of attributes From: kontakt@beberlei.de (Benjamin Eberlei) --0000000000002e73f405b06ed349 Content-Type: text/plain; charset="UTF-8" On Mon, Sep 28, 2020 at 2:58 PM Nicolas Grekas wrote: > > 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. > Can you clarify your reasoning here to get to this conclusion? because with #[Foo(Foo::BAR)] we also not trigger autoloading right now until newInstance() or getArguments() is called. This is the way it is working right now: https://gist.github.com/beberlei/8150f60abaab3b0a70ebb76ce6a379b0 Attributes allow constant expressions as arguments, the same which you can do in constant or property declarations for the default value. An approach with new NestedAttr() would work the same, only triggering autoload when argument needs to be evaluated for use. > > 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 > --0000000000002e73f405b06ed349--