Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119415 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 44952 invoked from network); 24 Jan 2023 11:36:40 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 24 Jan 2023 11:36:40 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BC9191804AA for ; Tue, 24 Jan 2023 03:36:39 -0800 (PST) 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, 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-yw1-f179.google.com (mail-yw1-f179.google.com [209.85.128.179]) (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 ; Tue, 24 Jan 2023 03:36:39 -0800 (PST) Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-4d59d518505so214101297b3.1 for ; Tue, 24 Jan 2023 03:36:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=d0uJ5Q2YyrfBIXyDTxsqWP1AXTVZ9W1bvyTC7NYdUQk=; b=jksAYj/cOylm9F+/Q7HjCnnVr/h4ZpF1+9nCWOI4N6/sa7vN8Z7Y331ZKu5zFuwqdo B1dTOwg+DNnlz2dCSjRa4Cu2jOFwY6+yyO5wiGDsbMwGpLh64l2hZcfj6Wl87a6F4RxG ldY5/g6I76oXKPCGG6ZawZgnFY4C9CUJrji7jfDAY4MJiiJ94mBcqPXbgtv+DmlY8JZ5 yzW+21WyV0BfTz7Zkzve8iXvdJI6PvTjBo+XXl9hoWYOFKI7OuwSCCpDGppPV5cT3tIU Lu7/Q5A3bIrIeI5MxMFzbRVK4f0Nc7b4dOpcILHZ7Eootr70qJPWNZ/S3aHXAY0khXMj wk3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=d0uJ5Q2YyrfBIXyDTxsqWP1AXTVZ9W1bvyTC7NYdUQk=; b=HCCsU+NDBUNLcFv/GO6v6neu5GnXshuTOIXgY9A2JnMlNgstcVTxvM8q5HVRb8hlUq C1ZZamJGfXq0BweRfXqSRpRBSSEYrlFczHa7iA26YjaPTp+7cBbyJ6H0vdYcr5yk0x18 lvZrEtyoWrPWJTS432LP0GMLEx2L2+2MzDJG8FVZkhi0VibXhUb8tvE8iK+ngLAS6mfU aNqy2pgDS7mzfiLuEz+QTl2KoZQdNubxsxnvPKiEKweh9htRR86GIZsSXmLAqh0VWNh2 AFmVm4sYsduBlaZkGbEx7vqdv+PiLUNEKGAY0NQPBeX4l8O1iL5weI+XgHXVG3LdTqJg AFJA== X-Gm-Message-State: AFqh2kpKirhT8WptQQBxNxpMPLger2mHpOZSaftZecCpz86zzqqmHMt8 QKUpEWgpLl1MuXlnecO6RBdIpiTAMFh1APGa7xk= X-Google-Smtp-Source: AMrXdXt5scxht5aw2TBj3f8fIZtC0JwIO0LMDHDIbju043NyfsNFRkvrD7Zvqni/x7K0TCsuRhOQmB6UvZ2/tzlwBQU= X-Received: by 2002:a81:351:0:b0:36c:aaa6:e571 with SMTP id 78-20020a810351000000b0036caaa6e571mr2487912ywd.467.1674560198657; Tue, 24 Jan 2023 03:36:38 -0800 (PST) MIME-Version: 1.0 References: <8f530a4a-bf48-4259-877e-16ebf8082936@app.fastmail.com> <9c97b0b1-e17e-4eec-8cf5-fad86aca2da6@app.fastmail.com> <87c1e01f-0ef0-4096-996c-030be1fab73f@app.fastmail.com> In-Reply-To: <87c1e01f-0ef0-4096-996c-030be1fab73f@app.fastmail.com> Date: Tue, 24 Jan 2023 12:36:27 +0100 Message-ID: To: Ollie Read Cc: =?UTF-8?Q?Bj=C3=B6rn_Larsson?= Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] Introduce the abiltiy to use the first-call-callable syntax on non-static methods, statically From: landers.robert@gmail.com (Robert Landers) On Tue, Jan 24, 2023 at 12:06 PM Ollie Read wrote: > > You're absolutely correct, the problem I was trying to solve was the ability to reference a method without throwing around magic strings, apologies if that wasn't clear. > > The whole idea, or rather, need/want for it came about because of time spent with Javas functional side, though I understand that's safer to do because of the way Java handles type safety. > > The ::class pseudo type is great for providing a classes FQN, and class-string is great for ensuring values are valid class strings when using static analysis, but we don't have anything for methods, outside of IDE completion. > > The solution wouldn't even need to generate a closure, TBH, it would generate something that could then be used in the same manner. > > Using the current features of PHP, I'd probably imagine something that does just about the same as this: > > $method = new ReflectionMethod(MyClass::class, 'method'); > > $collection->filter($method); > > Where the filter method does: > > foreach ($items as $item) { > if ($method->invoke($item)) { > // > } > } > > Although reflection doesn't have the overhead that everyone thinks it does, this is a less than ideal solution, but I think it accurately portrays what I'm looking for. > > --- > Best Regards, > *Ollie Read* > The ::class pseudo type is great for providing a classes FQN, and class-string is great for ensuring values are valid class strings when using static analysis, but we don't have anything for methods, outside of IDE completion. > > The solution wouldn't even need to generate a closure, TBH, it would generate something that could then be used in the same manner. In C#, they have the `nameof()` operator that returns the name of the symbol passed. So you still end up with a string, but the symbol can easily be refactored. https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/nameof Maybe something like this could help address the problem? Robert Landers Software Engineer Utrecht NL