Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120259 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 48730 invoked from network); 13 May 2023 10:37:05 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 May 2023 10:37:05 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 18F371804D0 for ; Sat, 13 May 2023 03:37:03 -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=-0.7 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 13 May 2023 03:37:02 -0700 (PDT) Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-3f4c6c4b425so25942115e9.2 for ; Sat, 13 May 2023 03:37:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683974221; x=1686566221; h=content-transfer-encoding:mime-version:message-id:references :in-reply-to:user-agent:subject:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=chFZwFs0C7HbHQ6JzIvyHBpv4L09HZkTnFN3w3xcGGY=; b=ZXdVA6YjtzbrW+Dz1s6bIrVxbN89Y9ZfqzdQy3/Plt40YHniY2exabDaA49tgdI6LH z9O+6q/gIrKbWqEXdaw5dX720OkQW5MAD6ByrXiHkHGRlPbgAWxzM9pzw3Tge1pY5NIt QpyO+otAS4//F0b/i72bDeEu8sdSBl/DsTTKLwF+v5lHvXhC48w254xLlPymvU6exoCO diCFVeKLJ7BScezcvyoqBj3J0Vcec+5lRUpIqITk2UQzQ3heAKi1mCsbdxz1cv9o46Nh EEtgtDRemALaR0kjY1upN81+DkA7frnxFP8nfoy+EHZspmM3sBjV2gsfv4mW098Vkh+L GUFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683974221; x=1686566221; h=content-transfer-encoding:mime-version:message-id:references :in-reply-to:user-agent:subject:to:from:date:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=chFZwFs0C7HbHQ6JzIvyHBpv4L09HZkTnFN3w3xcGGY=; b=TVJZqu8AAJa+vIdAC8rNGW+q7h5BKQz7KpbHcylLu5ByRXX+UbuD62Xtoj2pGCRbai f05wTLg5I7P20/W1oI2vG/TMoJ6ccNEw6w/jA5eItTBufVo3gJ3y9Dxj47JI3+oIo1qd aS5CAnuek6htXFPxnD1LluqaRnufAQ+bQllXmCgmClmo1VnKGagK5YnKJsA2/ljk2pbj 9VRFLRtuyu6CgfGMM0R6oQbcwCM5LlYJq692Rvswp6bRkksB04o8gbTzcszIdzg1ajv6 QX+jxQojx1y5+XxhNCy+KC6QXDZSPKLVjhSiabKw/JOH+vUZTX8z9Q471g+htWr6RnEG Jf2Q== X-Gm-Message-State: AC+VfDyhJW+YUZtwTAfZd1Caw4FHQbWTQt1J+M98Ffea12Fy180Grg7g +xtfHJQ8qLfaqDS+sVxhkVHnQ4wWWfM= X-Google-Smtp-Source: ACHHUZ7RZZ8A7viOlygtlj3zTqXXpGarbBVeaBi3NwZz1xJ2lpxp5xRZjDhtxaZShO4ENOm9kaG4sQ== X-Received: by 2002:a05:600c:243:b0:3f4:2b72:eaa9 with SMTP id 3-20020a05600c024300b003f42b72eaa9mr11478583wmj.8.1683974221217; Sat, 13 May 2023 03:37:01 -0700 (PDT) Received: from [127.0.0.1] (cpc83311-brig21-2-0-cust191.3-3.cable.virginm.net. [86.20.40.192]) by smtp.gmail.com with ESMTPSA id a24-20020a5d4578000000b003063938bf7bsm26187136wrc.86.2023.05.13.03.37.00 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 13 May 2023 03:37:00 -0700 (PDT) Date: Sat, 13 May 2023 11:36:59 +0100 To: internals User-Agent: K-9 Mail for Android In-Reply-To: References: Message-ID: <436378BB-FDFA-43BD-A633-C030C347E683@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] [Discussion] nameof From: rowan.collins@gmail.com (Rowan Tommins) On 13 May 2023 10:04:39 BST, Lydia de Jongh wrote: >I prefer a magic constant like `::name` instead of a function call as it >can be used in a wider scope; for example as a parameter in an Attribute= =2E Don't confuse the syntax with the implementation: "::class" isn't actually= a constant, and the proposed "nameof()" isn't actually a function; both ar= e just syntaxes understood by the compiler to generate strings according to= certain rules=2E The RFC explicitly mentions use in attributes: > The nameof() function is not necessarily a function in the traditional s= ense and can be used anywhere a string literal can be used (such as to defi= ne static constants, array keys, and attributes)=2E I'm lukewarm on the RFC myself - I can't think of many places I'd use it, = and some of the use cases feel like they would ideally not involve strings = at all=2E But I can't actually think of a good reason *not* to include it= =2E The one part of the RFC that surprised me was this: > When getting the name of constants and functions, the name will NOT be t= he full name, but the lexical name=2E This means that if the name is use'd,= it will be that name=2E However, if the full name is used in the nameof(),= the full name is returned=2E No reason is given *why* it works this way, and expanding the namespaces o= n a name is one of the most useful features of "::class"=2E Importantly, it= means that the string created can be passed to other contexts, and still r= efer to the same thing=2E For instance: use function Acme\bar as foo; =2E=2E=2E #[SomeAttribute(callback: nameof(foo(=2E=2E=2E))] =2E=2E=2E The attribute constructor, defined in a different file, can't do anything = useful with the string 'foo'; it needs to know the qualified name of the fu= nction the user referenced, 'Acme\bar'=2E Similarly, I'm not wholly clear why nameof(MyClass::method(=2E=2E=2E)) sho= uld evaluate to "method" rather than "MyClass::method" or indeed "Full\Name= spaceOf\MyClass::method"=2E Some more details on what exactly it evaluates = to for each type, and why, would be helpful=2E Regards, --=20 Rowan Tommins [IMSoP]