Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115327 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 72821 invoked from network); 6 Jul 2021 14:19:03 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Jul 2021 14:19:03 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6A2611804C9 for ; Tue, 6 Jul 2021 07:40:49 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,FREEMAIL_REPLY, 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-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (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, 6 Jul 2021 07:40:49 -0700 (PDT) Received: by mail-ej1-f43.google.com with SMTP id bu12so34626259ejb.0 for ; Tue, 06 Jul 2021 07:40:49 -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=a9hPK2xtht9GibwLPIz9+KLUvK3kxXWY/MNnweLYy9w=; b=KDZi5Y6mU6k6/5/X15Y5VSkvKX7c2BL0Fsxv7XiLjDsP6vW06mNKWlOivff3WEpGhc xqQg2+pv/5jsB+/Ckem+iW+c5hXpTXHk2du1poM0iTEIxXxDPRqFwndNGEyGzOJDKo3Z xCR8h9ytPd82avKnmr5h2aEi/98aVqcGnveox5h53lRROVGmArRYBHeLxJVi3WLqzqDl BEticMWEIFPJLLnqu7evrnxMMiKv9tkbMkhvH6ZBRs1LnV+vvt3TqIxUR44I4hzXrba1 1LxTrdkZoizGKyvtmEV8M+44cdIMDHRt2CYY9OS7y/P/lfE+LuQo/zzYClNGy+TnDpM+ uzFg== 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=a9hPK2xtht9GibwLPIz9+KLUvK3kxXWY/MNnweLYy9w=; b=VQfVbTfyro3PRnildzY9zdPNccbntS4PBAz+3tMVykWeCKMpk1W1BYNZ3h8EOFQk00 fTqiH79PAnSoa8zwKtPok3HR4WX+8Xh86P6pm9IfqaypvTUoQA9bC4ryt9MsCrNr2qhO Ncn6Ycd4OPT5ouGpyJj5DCeNBZJRbP2y9dUC5L4kZL2tHH/Sv7GCfiA9SzexVJV6Jqmb LY6asZq6pimIZqUwkbpaf4cyF7PxIhqUDT5KdxBXdQe0R+F2jK1IH/exVq2SMO41bI9g ajVsZuOk04bVT8vzPeFkabETJHLzpUAnWrrV84+5zihpokCyA+s1Wz+eDsVMaXgMQeyt HWNg== X-Gm-Message-State: AOAM530zMO7TkW/SFU3LOSWRfQ24IHIUPxR6u4oyQnEsPqe3YF2PmQSh ZQR2xuxU6ZM7hU9Mqjbe+73jp4PMT1EJx8kPCac= X-Google-Smtp-Source: ABdhPJwE8Sy1f8stgAOhZmwMS8xTeq8RnC4k5fDmH43aINlsRJfCVfvEThGyYsAqK5HxJQMbClt1pVdeCggPo8k5GZ8= X-Received: by 2002:a17:906:b296:: with SMTP id q22mr12573560ejz.313.1625582445983; Tue, 06 Jul 2021 07:40:45 -0700 (PDT) MIME-Version: 1.0 References: <34e76830-043f-3bae-4d60-9871010da0ed@gmail.com> In-Reply-To: Date: Tue, 6 Jul 2021 16:40:34 +0200 Message-ID: To: Nikita Popov Cc: Benjamin Eberlei , Rowan Tommins , PHP Internals Content-Type: multipart/alternative; boundary="0000000000003efc3805c67568d8" Subject: Re: [PHP-DEV] [Vote] New in initializers From: nicolas.grekas+php@gmail.com (Nicolas Grekas) --0000000000003efc3805c67568d8 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Le mar. 6 juil. 2021 =C3=A0 15:38, Nikita Popov a = =C3=A9crit : > On Tue, Jul 6, 2021 at 2:30 PM Nicolas Grekas < > nicolas.grekas+php@gmail.com> wrote: > >> >> > > This is not 100% correct, you can have an attribte #[Foo(Foo::class)= ] >>> and >>> > > then calling ReflectionAttribute::getArguments would also require t= o >>> > > resolve the type Foo. So this is not different than what could happ= en >>> > right >>> > > now already. >>> > >>> > >>> > Despite its name, "::class" doesn't care about class definitions, it >>> > just performs a string substitution based on the "namespace" and "use= " >>> > statements in the current file. >>> > >>> > In most cases, that happens entirely at compile time, so the followin= g >>> > two source files compile identically: >>> > >>> >>> Hah, I realized after sending the example was bad :) I should have used >>> an >>> example using actual constants (vs magic ones): >>> >>> #[Foo(Foo::BAR)] >>> >>> This would trigger autoloading and resolving during getArguments() >>> >> >> >> Right! >> >> Extending on my proposal, getUninitializedArguments() could return a >> ReflectionConstant in place of such values. >> > > This doesn't extend to any more complex scenario: It's not just > #[Foo(A::B)], it could also be #[Foo(A::FLAG_1 | A::FLAG_2)] and so on. T= he > only way to do this is to go all the way back to Dmitry's attribute > proposal (https://wiki.php.net/rfc/attributes) which allows fetching the > AST of attribute arguments. That could represent arbitrary arguments > without evaluating them. (In fact, that proposal also allowed attribute > arguments that PHP cannot constant-evaluate at all.) > > I also think that viewing this as "nested attributes" is not quite the > right way to think about it. Yes, the Assert\All use case is nested > attributes, but that's just a special case. More generally this just allo= ws > you to use an object as an attribute argument, and that object does not > necessarily have to be an attribute itself. To give a silly example, if w= e > were to write argument and return types as attributes, you could have > something like #[ReturnType(new IntersectionType(Foo::class, Bar::class))= ], > where IntersectionType is just the representation of a particular type, b= ut > is not (and shouldn't be) an attribute itself. > Types are a good example of a structure that the language already knows how to parse without actually requiring all symbols to be loaded: Foo|Bar doesn't require having both types loaded to work. I think we don't need to account for constants in my scenario. ReflectionAttribute::getUninitializedArguments() would then only replace objects with uninitialized placeholders that represent their class and arguments. That should cover the need. --0000000000003efc3805c67568d8--