Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119680 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 9319 invoked from network); 10 Mar 2023 19:53:24 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 10 Mar 2023 19:53:24 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 852FB18037E for ; Fri, 10 Mar 2023 11:53:20 -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.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS29838 64.147.123.0/24 X-Spam-Virus: No X-Envelope-From: Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) (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 ; Fri, 10 Mar 2023 11:53:19 -0800 (PST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id C3BC53200970 for ; Fri, 10 Mar 2023 14:53:18 -0500 (EST) Received: from imap50 ([10.202.2.100]) by compute4.internal (MEProxy); Fri, 10 Mar 2023 14:53:18 -0500 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=1678477998; x= 1678564398; bh=zACxipacKu6Ehmti9mUIhulolCQ8H+8fQXKQununBnE=; b=R 7VZR5ybk253Rr2MoN8p/EOD8RiPCPjXVp6aHgeOeyWzMj5NoWaXscoPjwDn+hANT lb8Ibh8w0Iu63rdSbRHAfXbSVMRTzxw46+OzhHhLGhaL8Bdml4SShFQiLI5PpFyn V4rLW92NTJ3MlYG08YzY3SRhK7OtIj1++ZyghWKqJApjBE05os/G2gyZGILauShb zjhEgfHHYJFOv/X6du+d8PWsk7517q8ppBLr7rTocaX8a8SQ5OIwmNOVeWjhYh7s 1YYdjqHyiyLB4Zz/8Kadag7EtQECA7LVu+AELhETM8dcfHZ8NxR7VBnp8ON5h2qg 5LAVmDVe2ukveiO4annVA== 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=1678477998; x=1678564398; bh=zACxipacKu6Eh mti9mUIhulolCQ8H+8fQXKQununBnE=; b=mPHfvL7n5FFDUVgFTTnIB75rWa7Pz 9NBMT7u+wEC21okONmR6jKRQb1En67XyzHnG7FSfGIoPaBJiQl/obfzh7l33EdK8 2LabE4cIDqDkxcFFFwitcDHkZhvqHI6WyNgD/XM/MLRxCFog2WPGWEpZXxvucETt 0RKNyuICQkl9K20kzGl/fD7hUMG51/Vox5zDayNQbUmxOqBEAdmRxnzWue6sGeqd iKWzvTwlZO9p0scbWYwm6d5XrY6j2mx5rwm7UnLd8hoNRyF36Tzcbm3lYptkKkHm /7STI5uWRpnHNG06z7l8Nrs8AdtluRqxldkT3pSPfj59Q7PbHjMbSJNGw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvddukedguddvkecutefuodetggdotefrod 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 268CA1700089; Fri, 10 Mar 2023 14:53:18 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-206-g57c8fdedf8-fm-20230227.001-g57c8fded Mime-Version: 1.0 Message-ID: In-Reply-To: References: Date: Fri, 10 Mar 2023 13:52:57 -0600 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] First-class callable partial application From: larry@garfieldtech.com ("Larry Garfield") On Fri, Mar 10, 2023, at 1:04 PM, Eugene Sidelnyk wrote: > Hello internals! > I'm just wondering why First class callable syntax doesn't allow partial > application? > Recently I stumbled across following scenario where it could be really > useful: > > ``` > public function __invoke(SendOtpCommand $command) > { > $this->cache->get($command->getPhone(), $this->storeOtp($command, > ...)); > } > > private function storeOtp(SendOtpCommand $command, ItemInterface $item) > { > // some logic > } > ``` > > In this example, I supposed that the closure created will accept a single > parameter $item, and when it is called back, method storeOtp will accept > both $command and $item. As it turned out to be, it doesn't really work > this way. > > Another simplified example: > > ``` > // partial application > foo(bar(1, ...)); > > function foo(Closure $closure) > { > $closure(2); > } > > function bar(int $a, int $b) > { > var_dump($a, $b); // 1, 2 > } > ``` > > Closure in foo accepts only one parameter. But when it is actually > dispatched, bar is called with two arguments. > > Are there any pitfalls, which prevent implementation of this nifty feature? There actually was an RFC for full partial application a few years ago: https://wiki.php.net/rfc/partial_function_application The main drawback is that in order to work, it had to do some very tricksy things with very critical parts of the code (how functions get called). Enough people felt that was too risky for the functionality and it didn't pass. First-class-callables were deliberately submitted (https://wiki.php.net/rfc/first_class_callable_syntax) as a sort of "junior version" of partial function application that could be done with far less invasive changes. I'd *love* to see some form of PFA make a come-back, either with a simpler implementation or a reduced scope that allows for a simpler implementation. I am not aware of anyone actively working on it at the moment, though. (If anyone is, please speak up!) --Larry Garfield