Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108496 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 91939 invoked from network); 11 Feb 2020 20:54:37 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Feb 2020 20:54:37 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BE069180538 for ; Tue, 11 Feb 2020 11:08:34 -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.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS,SUBJ_ALL_CAPS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS24940 116.202.0.0/16 X-Spam-Virus: No X-Envelope-From: Received: from outbound.soverin.net (outbound.soverin.net [116.202.65.215]) (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, 11 Feb 2020 11:08:33 -0800 (PST) Received: from smtp.freedom.nl (unknown [10.10.3.36]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by outbound.soverin.net (Postfix) with ESMTPS id 2E8B7601FA; Tue, 11 Feb 2020 19:08:32 +0000 (UTC) Received: from smtp.freedom.nl (smtp.freedom.nl [116.202.65.211]) by soverin.net DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=freedom.nl; s=default; t=1581448111; bh=vHGOdrl3vbfYj4+gHZSmKBzY/FWMR8qhgdhMA/Uo1tc=; h=Subject:To:References:From:Date:In-Reply-To:From; b=R4z6JAhZ42c4ZgylYio8nx8NDtluz3wpmATDI5I4WYxkXRbKdC1BR0RbDOcecPTrs lNV9FNq5wDxB61YegTmxIWvV6JogIjZfbvrBJ0tgzjuyMPhsLYTwcn4ZYSHKC1IBSI JodBSBWcTOw/+n6PIVyzJ2b5nG0twUj9AYVKV1Qo= DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=freedom.nl; s=default; t=1581448112; bh=vHGOdrl3vbfYj4+gHZSmKBzY/FWMR8qhgdhMA/Uo1tc=; h=Subject:To:References:From:Date:In-Reply-To:From; b=j9haa3nJIi6thztXO5Pm8z9xyrja+NjEdybxEJYkEvIk+x6GscvKemjnELeqhTTJm FJuYp4zvcWHPP/t+i14VYzwlJALM0hc/cwNQr7Xa8vSuOBPadFpG/p0U6c7lDJgcVK ysu4tojE7ajtMUrDVjohZ9Kg4KamTsOcy6RJpmAE= To: internals@lists.php.net, Larry Garfield , Dan Ackroyd References: Autocrypt: addr=d.h.j.takken@freedom.nl; keydata= xjMEXimHTRYJKwYBBAHaRw8BAQdAzvRUI24yOGvteVk9N6VKIt425fNgg0P1rvD2WQLGP+fN JERpayBUYWtrZW4gPGQuaC5qLnRha2tlbkBmcmVlZG9tLm5sPsKtBBMWCAA+FiEEvtrj9qG2 TA2YmjvLhef0X6cSlpAFAl4ph00CGwMFCQlmAYAFCwkIBwIGFQoJCAsCBBYCAwECHgECF4AA IQkQhef0X6cSlpAWIQS+2uP2obZMDZiaO8uF5/RfpxKWkPywAQChh9Z1jSvitkT3sIipwMlk dnUlYY5Ue3lHBBhF6pQUOwD/XtEz/fsjvqE/GpjJhXpxNodwKjLhaUiFe9qRwwH/5QXOOARe KYdNEgorBgEEAZdVAQUBAQdAMNSCUI0PnOjjrFKZDAFRQzKLVDCINuFNgsXh0snmlUwDAQgH wpUEGBYIACYWIQS+2uP2obZMDZiaO8uF5/RfpxKWkAUCXimHTQIbDAUJCWYBgAAhCRCF5/Rf pxKWkBYhBL7a4/ahtkwNmJo7y4Xn9F+nEpaQEYUA/2mZ3uEN0JTRUZbxHGBMB4IhQw0cdIML FpFrTycqUCXCAQD5rWXomBWVD/DRHk7O3KjNsek9F1DEZgGeZ5pPmNF/Dg== Message-ID: Date: Tue, 11 Feb 2020 20:08:28 +0100 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US X-Virus-Scanned: clamav-milter 0.102.1 at c03mi01 X-Virus-Status: Clean Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] From: d.h.j.takken@freedom.nl (Dik Takken) On 11-02-2020 17:48, Dan Ackroyd wrote: > I didn't include the following in that RFC, because I thought it would > be too controversial, but I think it's worth considering a new syntax > for this. > > Given the code: > > function foo(); > class Zoq { > public function Fot() {} > public static function Pik() {} > } > $obj = new Zoq(); > > > Then these: > > $(foo); > $($obj, Fot); > $(Zoq, Fot); > > Would be equivalent to: > > Closure::fromCallable('foo'); > Closure::fromCallable([$obj, 'Fot']); > Closure::fromCallable('Zoq::Fot'); or Closure::fromCallable(['Zoq', 'Fot']); > > Or similar. Given the fact that $() would only accept functions and methods as argument, this idea could be taken one step further by writing: $(foo); $($obj->Fot); $(Zoq::Fot); Referring to a method like this is normally not possible because it is ambiguous. However, wrapped inside $(), which only accepts functions and methods, the ambiguity disappears. The $() syntax is nice and short. And something completely new. As new syntax can only be 'spent' once, more familiar alternatives should be explored as well. Thinking about the existing list() and array() syntax, another possibility could be: closure(foo); closure($obj->Fot); closure(Zoq::Fot); It is slightly longer but more familiar syntax. On 11-02-2020 19:46, Larry Garfield wrote: > > I would love a nicer way to reference function names; it's really ugly to do functional code in PHP otherwise, or even just dynamic function logic within a namespace. If I never have to write $fn = __NAMESPACE__ . '\a_func' again, it will be too soon. :-) Perhaps Larry can convince us all to go for something like $() by posting a fabulous functional programming example? Regards, Dik Takken