Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120321 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 36273 invoked from network); 16 May 2023 21:56:39 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 May 2023 21:56:39 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 34EAE180209 for ; Tue, 16 May 2023 14:56:39 -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.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS19151 66.111.4.0/24 X-Spam-Virus: No X-Envelope-From: Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 16 May 2023 14:56:38 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 74D605C00C1 for ; Tue, 16 May 2023 17:56:38 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute4.internal (MEProxy); Tue, 16 May 2023 17:56:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-type:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1684274198; x= 1684360598; bh=d+2XgAAYBM8Akkw04aeiBzhxlksfEL+UmyCyWLf4trs=; b=I /ciC125dZlzzrDof5ywMxshozqhWFzmfhFIPrcCbr8BZiDjMtIaq91F0vTnHixvh /uKxN9A/3z1xQzmxGipQAAnFOpCTAz1Gkf5GpBWxOLFN+7E1qTFgWn7mA7k/p87y HAw6qVpQhihB5NWql6wk7Qt6XVM2WU02EmAZNUEIz4v46tevG/P/CeebZe+D4LdR rtrV2+ANESEYR8OsV1uKs6XXnWCj5SQ51bYkkneo6dTaG+hdO3mIr1qX17LdHvYm GCgnR4pUQ7nER/egc/RtYg14aoKqBCfzGyW0kx4vGiHOwF0cxLmdrdFXjtrkvece PHrN2nNF9ag1sHC2jdgDA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1684274198; x=1684360598; bh=d+2XgAAYBM8Ak kw04aeiBzhxlksfEL+UmyCyWLf4trs=; b=pdvoGLK/IbZ64laXQR+sZFahOZgqF 2CgzU6Ti/RZcsyHqbbVpHdFNZQa7yJBtaFIujTa8YCtbRJcvJYIsIxrdO+BPDwLr +xYZGgzuTcVb14AgcNrPDeUsL76ivV4Jcn+jwapdruTf6/IERHG/aLUv0waHRxzb fxvOuQsuI35YAK9faSb6nuDOP0jSX6ecBjsRKI+J+Z+JU8N9Y/70mf32oPoEjyqZ x39y9qOzaBd30AapkYZMjqcSvXWYprDCpH3HyCeafhdHlnJP5VfmtCf8Y9EMRbAJ vvc5MaoBSX6l92dyi3QjuGelNPOeKDpbq66Kc+4pvHAPShavMzIioCCCw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeehledgudeijecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepveehhedvveejledvvefgleevffdtjeekledvkeeg heffgfeivdejhffhledtudetnecuffhomhgrihhnpehphhhprdhnvghtnecuvehluhhsth gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheplhgrrhhrhiesghgrrhhf ihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 3B5EE1700089; Tue, 16 May 2023 17:56:38 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-431-g1d6a3ebb56-fm-20230511.001-g1d6a3ebb Mime-Version: 1.0 Message-ID: <5e35344e-e885-4b65-8f86-2cb43330af46@app.fastmail.com> In-Reply-To: References: Date: Tue, 16 May 2023 21:56:16 +0000 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] [RFC] [Discussion] nameof From: larry@garfieldtech.com ("Larry Garfield") On Sat, May 13, 2023, at 7:27 AM, Robert Landers wrote: > Hello Internals, > > It is with much trepidation and excitement that I'd like to announce > the `nameof` RFC (https://wiki.php.net/rfc/nameof). It has changed > quite a bit in the last couple of days, so if you haven't seen the > latest draft, please check it out. > > Essentially, it allows using `nameof()` anywhere a string can be used, > even in static contexts. From a developer's perspective, it is a > string and from the engine's perspective, it is also mostly a string > (depending on how deep we want to go on error checking -- see the > RFC). > > If anything is unclear or if I missed something, please let me know. > > Robert Landers > Software Engineer > Utrecht NL Some concrete use cases that I know I run into, and would thus be what I'd hope an RFC like this would resolve: Router::addRoute('\my\space\my_action_function`); Right now that has to be a string with a full namespace. You cannot use a FCC here, because you want to use this data to compile the router somehow. So in this case we want the full namespace. (Ignore function autoloading for now.) Router::addRoute(MyClass::actionMethod); Various frameworks have different custom syntaxes for this case. It's also not clear if this refers to a static method, or a "instantiate this out of the container first and then call this method" approach. In these cases, we would want the full class name, and the method name on its own, as separate strings. In my FP library, I have code like this: function prop(string $prop): \Closure { return static fn (object $o): mixed => $o->$prop; } function method(string $method, ...$args): \Closure { return static fn (object $o): mixed => $o->$method(...$args); } Which you can then use in a pipe, like so: pipe($someObject, method('foo'), prop('bar')); Or, more realistically, you'd use method() and prop() in a map or filter call within the pipe. In this case, you want just the method/property name on its own, without a namespace, because it will be used in the context of an object to be named later. How would nameof() handle each of these cases? --Larry Garfield