Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115322 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 62085 invoked from network); 6 Jul 2021 13:16:41 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Jul 2021 13:16:41 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 52E541804CC for ; Tue, 6 Jul 2021 06:38:27 -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-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (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 06:38:27 -0700 (PDT) Received: by mail-lj1-f177.google.com with SMTP id r16so29111755ljk.9 for ; Tue, 06 Jul 2021 06:38:27 -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=oiHJTNHvekHAsYpYZWvLqH+MQZiLdVQ2eHWyv3g0nUQ=; b=kc9dMNEZux1TzSHRySHnsEK3mXcRoCPpr6eUdvtDnXEIfXJVydSnYdmjdWD7yHjpKH OB5yyX30DBrtWVFk5kkJFDPlBxA41oMuNKXABw7xn7kLFrb5UeahRlpkHnVe4GMjBYiw tGC42Wegu2DxVUWe0SINqmibMF6uU7DUHylTF90vI2h476mtTi0E4v4wzHJT1kgHyXRc 5IbK3+GGAbVK4z31DzmTBjXX7but+LLvEz76Oge7HuYxNFq046HFqbAkBY5dKZWw9V2p Edvil8ixAjSWQ0IbWqhbseoE03/4XzcSo/XQi4l3vXBPpWoDsiRvne05ielC2g6rDRB+ jvSA== 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=oiHJTNHvekHAsYpYZWvLqH+MQZiLdVQ2eHWyv3g0nUQ=; b=RLk5lyn4lXz9emWjKqbHD51B8hNUh6cXzcFFrelHLO/4qALbCgBYIJzl4rdRFyny9O kZ8NYCjuh4P8NcTP1mHp2xq3GNzSMLx1SPkV1ObzfxZN0vyzOxfrQQn+ab4gVrKV2pEE 7SuIn9eGRO2ImlK9Jiz7x2PX/x/6eOaY4stHwuJd2QD/XxyMfLrjh6WjvTzJ5A2sUKeh 7I6pzPjheuBRZk2293cOO3YZncxJRJwuahzmRU5OsI2ftovQAkhOZXS7GnUB8ovpzDf4 mI8zbJZRYwrvQo+PEgtSwETJFgYboQWafvc5lCcb4RjTsKSdoRaXcHh6MxRxwiIgIwHo vjHA== X-Gm-Message-State: AOAM531+EWR3J8jID0LAIVAVS1KXsyOtHDphMXxY3PPD9s4T8UVsNT4b tPJJ8OLJiMMs4smOEqrVxHTn0wJtFpUzXSkQDAY= X-Google-Smtp-Source: ABdhPJyxR6Ehp01mpCz1FeDjgyTql5/HR9MKlfceuQUUtJpmfpv+j2VAWu8eXZbZQdP7bCo39fdqOqUrid1CSid2FYQ= X-Received: by 2002:a2e:a279:: with SMTP id k25mr15819352ljm.29.1625578704559; Tue, 06 Jul 2021 06:38:24 -0700 (PDT) MIME-Version: 1.0 References: <34e76830-043f-3bae-4d60-9871010da0ed@gmail.com> In-Reply-To: Date: Tue, 6 Jul 2021 15:38:08 +0200 Message-ID: To: Nicolas Grekas Cc: Benjamin Eberlei , Rowan Tommins , PHP Internals Content-Type: multipart/alternative; boundary="0000000000003d621505c6748974" Subject: Re: [PHP-DEV] [Vote] New in initializers From: nikita.ppv@gmail.com (Nikita Popov) --0000000000003d621505c6748974 Content-Type: text/plain; charset="UTF-8" On Tue, Jul 6, 2021 at 2:30 PM Nicolas Grekas wrote: > > > > This is not 100% correct, you can have an attribte #[Foo(Foo::class)] >> and >> > > then calling ReflectionAttribute::getArguments would also require to >> > > resolve the type Foo. So this is not different than what could happen >> > 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 following >> > 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. The 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 allows 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 we 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, but is not (and shouldn't be) an attribute itself. Regards, Nikita --0000000000003d621505c6748974--