Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115316 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 44101 invoked from network); 6 Jul 2021 10:23:09 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Jul 2021 10:23:09 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 390DE180501 for ; Tue, 6 Jul 2021 03:44:53 -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-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (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 03:44:52 -0700 (PDT) Received: by mail-ej1-f47.google.com with SMTP id o5so33451753ejy.7 for ; Tue, 06 Jul 2021 03:44: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=2ZcRwMBeXQ3M0mFnBitR/9SP+bOjAiK1NYHU/3zVjSE=; b=n+rXCf9w8WaIyUj+kV8zoLH18jrRSJX9V2fjazSKc1IOo+TbXDaJwd2YSPd74E5RXX FMoKlBV0mswDrxiKF0hrGe4yRT1j6kNnLgFQ1vTq4Ab/PCvEqJHjy2ibCPaYcz4U+T8L CC9PWjBLsUjvtOm+79QQdJlIzoQJY352VY1u7DGg20v5wvTwPWjcDPJvt14c/KCUme4q M4QshJZzDJexzjwNDGq9ZDXSpS298hnxUF7QfKQp5ake0csvQijNGlbd+RJi4q1/If/l v7MMITL4BQpDDXa6Nho39gP++j5IFqz833X+ocNV2YeUyilWCBaHUWHI1Gykp+n69215 BkOw== 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=2ZcRwMBeXQ3M0mFnBitR/9SP+bOjAiK1NYHU/3zVjSE=; b=jWMjawOIfsP6lYFZE7nPxWC5YgFsSQdkO5Rby7Flsrd3Eshs79Z/Gvsh1C7A2EQP32 bp4Z8w3zYGBTYmxHolFzkOew7a2kZXoN+cWprUdW1a8nSYeKl2kkMBrdlmFkZP7MstxQ u9blRdADcv870Dwb4vkisibWE8FLBllQZQkmi4F8A6nb15zmpAMLuSAMOX7iGH1XuOnO rszh6yuYU3fo0FNjWcRxKY9oScFyZfE/7VK6BJ9pmvjoPv0I38/y9eHzFXP7kg53V15w +epZ7l9Tx8sbv8nYJZMSicPQrGQMetBIzLDK/UnJup7LXjvXzFGOQr/ZsHuCmX81JDZo VJOw== X-Gm-Message-State: AOAM531aJ67WWPEnDxeQ2nYRF/ctbaDPeoCPVyC+d4R/kkYsgSXJ9lY4 VFSONy15ptm6QAmiOQcdVIdisE5ctXapbGXOQ4E= X-Google-Smtp-Source: ABdhPJzhS25teM9NhPYOBxFyXACtVbd0O7SI+nOeG4j2w1kj+/b5E67Ma4w4K/mlVOWGRDhVuRg5nClYTL8WaQX/8j0= X-Received: by 2002:a17:906:b296:: with SMTP id q22mr11469909ejz.313.1625568290216; Tue, 06 Jul 2021 03:44:50 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 6 Jul 2021 12:44:38 +0200 Message-ID: To: Benjamin Eberlei Cc: Nikita Popov , PHP internals Content-Type: multipart/alternative; boundary="0000000000007f21ef05c6721ca1" Subject: Re: [PHP-DEV] [Vote] New in initializers From: nicolas.grekas+php@gmail.com (Nicolas Grekas) --0000000000007f21ef05c6721ca1 Content-Type: text/plain; charset="UTF-8" > > I've opened voting on https://wiki.php.net/rfc/new_in_initializers. Voting >> > will close on 2021-07-14. >> > >> > Note that relative to the original RFC, new support is limited to >> parameter >> > default values, attribute arguments, static variable initializers and >> > global constant initializers, and not supported in property initializers >> > and class constant initializers. The discussion thread >> > https://externals.io/message/113347 has some extensive information on >> how >> > we got here. >> > >> >> I voted yes and I'm happy this will come to PHP. >> >> I realized I still have one concern that I want to share here, related to >> attributes: >> The RFC breaks the possibility to parse the arguments of an attribute in a >> generic and safe way. >> What I mean is that right now, attributes can be inspected while the >> corresponding classes are not installed, due eg to a missing optional >> dependency. >> > > 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. > Right. Yet this can be easily worked around by using a string literal, so at least this issue can be avoided with a CS fixer when it matters. What you can do is use `ReflectionAttribute::getName()` to filter the > attributes you want to work on and only then call getArguments(). > Yes, my comment is about nested instances, not the root ones. #[Any(new Foo, new Bar)] <= Foo and Bar classes have to be defined, but this should be inspectable without instantiation, like root attributes. > This behavior is what makes attributes truly declarative: one can ignore >> what they don't care about. Extra semantics can be carried out by classes >> without making the related attributes a mandatory dependency. >> >> I think there is a way to preserve this behavior and that we should look >> for it. >> >> If I may propose one: we might add a new >> ReflectionAttribute::getUninitializedArguments() method, that would return >> the same as ReflectionAttribute::getArguments(), except that it would put >> a >> ReflectionAttribute (or similar) instance in place of objects in the data >> structure. As a corollary, we might also want to enforce that only child >> classes of the Attribute class can be nested inside another Attribute (at >> least if we want to reuse ReflectionAttribute as a placeholder.) >> > > A function like this could return all arguments that are not AST Nodes but > "literals" (instances of scalar / array types). > Foo::class or new Foo() are both AST Node types that are resolved the same > way in `getArguments`. > I guess so, but I'm not sure to get the exact point you want to make here :) --0000000000007f21ef05c6721ca1--