Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128223 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id 1E80E1A00BC for ; Fri, 25 Jul 2025 10:15:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1753438439; bh=voUD52BeqVXtsr4IdUrRr8EVBolId+rIiFzrfMqzYJ8=; h=Date:Subject:To:References:From:In-Reply-To:From; b=fHPSHlAkCQUxd6/bujzPQpPIe/ezZfEcu/+fEEZXVY14hr8W7AihuXp+6I8QDVL1m DVL40E8mDGdGpcqkWSalynXxcBchovLDqvjtvl331b0JUqSWT1NNTqRAVoiRXlC9gk 5mNjAjMTDCaO87S+yhVikNBqDDood1KSCL9zWtlUpweBiM/vLVKiFq1wQ+De+UWT9/ PqxlJLwhg3EFzDAlZnxclt787dJMuWJg12Wd7l1JmTrdnf93h2cNCneoEL/dfv4gfp +JBHu1KJ9KDwzd5IhOcxMoEDsIgVsRtbCr3ZhkM3VtG1sA6PHki5EnvKdUe5jWez/4 NnlENOtj0kSsw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E7ACA1801D4 for ; Fri, 25 Jul 2025 10:13:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) 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,DMARC_PASS,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 25 Jul 2025 10:13:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1753438540; bh=iy/XVFf622Ck4agvNPSK8PtE3siqx4YMcxfK0Yt8kXE=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type:from:to:cc:subject:message-id; b=W24Rj0DO52FbZIn3ePLgssMQec1JPLWtYbi+xd4hwPzJUMzm6OduVBd3RWXLp8MvG 2GPxY3CMGXsqOxnPS8I62iSOpuNkSplCh/1del3M/qRVv7BvJ503fHNqm6MKKe9pi2 cgCBzev7BRbHE6wW02CviUAgE8lhNZ16x2WRfllC0/fEuNMixaxk1mmg9joVH3giyn wkvhwpeLp5bD+XFEkWIMY4gIueLHwdL/HonctLWjyOF9VbhW4IhF7erWCe7v39gyo5 RsugoIcWxKS9Aqoy9CG1FleqhxNqIRSeqIblKkQVi6B5AmU//2AQxKleWezaml1q/6 3Y3BAKSWOYBMg== Message-ID: <06c74ba1-2a5a-4f0f-bac3-81825c4017a3@bastelstu.be> Date: Fri, 25 Jul 2025 12:15:38 +0200 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Subject: Re: [PHP-DEV] [RFC] Partial Function Application v2 To: Larry Garfield , php internals References: <52dbe5236df460958644677c781513c3@bastelstu.be> <395ee57ca13b16ab09301f9bee6f07b9@bastelstu.be> <779a8062-72d7-405a-b15c-136c8e971f7f@app.fastmail.com> Content-Language: en-US In-Reply-To: <779a8062-72d7-405a-b15c-136c8e971f7f@app.fastmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=C3=BCsterhus?=) Hi On 7/24/25 16:04, Larry Garfield wrote: >>> I don't think they should. Specifically the (1) and (3) should not. My >>> expectation is that: >>> >>> $f = foo(a: ?, b: 2, c: ?); >>> $f(1, 3); // calls foo(1, 2, 3); >>> >>> and >>> >>> $f = foo(c: ?, b: 2, a: ?); >>> $f(1, 3); // calls foo(3, 2, 1); >>> >>> The order of the question marks should match the order of the >>> parameters in the resulting Closure, which is not necessarily the order >>> of the order parameters of the original function. > > That would be inconsistent with how named arguments work anywhere else. With a regular function call, you can list named args in any order you feel like and the engine will reorder them for you back to the original defined order. (My IDE keeps yelling at me to put them in order, but that's an IDE problem, not a language problem.) Having PFA behave differently feels needlessly confusing, especially since positional placeholders are supported, too. The point is that PFA defines not just a function *call*, but also a function *definition* at the same time. This is what I meant by “you are dealing with two parameter lists”. What you correctly describe is the behavior of named arguments in a function *call*. What we do not have yet is the behavior for a function *definition* and I'm arguing that the proposed behavior in the RFC is wrong. Using the existing example of: function foo(int $a, int $b, int $c) {} For the first case of: $f = foo(a: ?, b: 2, c: ?); My mental model desugars that to: $f = fn ($a, $c) => foo(a: $a, b: 2, c: $c); And for the second case: $f = foo(c: ?, b: 2, a: ?); it desugars to: $f = fn ($c, $a) => foo(c: $c, b: 2, a: $a); The order of the named parameters in the inner function call to `foo()` changed, but as you said, the engine will make sure to place them into the appropriate parameters, resulting in a successful call to `foo()`. But it does not follow that the parameters of the PFA Closure also need to be reordered, they can (and should) be completely independent, because PFA allows to “call named parameters using positional arguments”. Basically when I'm reading the signature: $f = foo(c: ?, b: 2, a: ?); $f(1, 3); I'm reading the question-marks from “left to right” in positional order and then when I call `$f` using positional arguments, I'm expecting the question-marks to be filled in in positional order. ------ I've also asked a friend of mine, who had only skimmed the RFC a while ago, without explaining anything: function foo($a, $b, $c) { var_dump($a, $b, $c); } $f = foo(c: ?, b: 2, a: ?); $f(1, 3); What would your intuitive expectation what this would output? They answered "3 2 1" and after I clarified that the RFC specifies this as "1 2 3", their first reaction was "What?", followed by "there are two placeholders, they are filled in left-to-right". > > $f = foo(?, a: ?, b: ?) > > It's not obvious to me what should happen there. Does that implicitly mean $c is now the first argument? That's not at all apparent from the syntax. I believe this should be a compiler error, because `$a` is specified twice. At least it would be for a normal function call: https://3v4l.org/oVMLC > Similarly, in a longer example: > > foo ($a, $b, $c, $d, $e, $f); > > $f = foo(?, 3, b: ?, e: ?, ...); > > That already takes a moment of thought to know what's going on, despite being legal. (A value is provided for $c, but nothing else.) Having that also change the order to... I think it would be f($a, $b, $e, $d, $f) ? Just raises the effort to grok it even further. Likewise `b` is specified twice. Best regards Tim Düsterhus