Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130033 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 068A31A00BC for ; Fri, 6 Feb 2026 16:43:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1770396217; bh=jNidSfrYoTxFm+SCIf0SuyCWwpd/q+8CvJZ16PX1TYA=; h=Date:Subject:To:References:From:In-Reply-To:From; b=kPtnwaNdefgHEJpaOQicHzy9e76Bk8PgpQd6WjbSFZwQj2zZK2ChctpUYcgi9Sls1 JGpr9SIbuLBhRp99XgQ/5rNMsxFXDmATuFLSJ5K87IDiMUXoLr19huFI0e3QRn80fQ t3F8ctA6LipWZ/0lE1Kd6DBIDVq5ixqEljK6mOSlU+qq/rlOKs55PS7h2CkvJD397l GcF/PAbRi7F+AWPvQj8xVPG9j+cOAdNqfqHa1jqyPTmfbJouS9mI7icWI1jvDlensj wqgptFi5LOAWFcyWBMhODKuyPVsEialPAJs1Md35eHdptohmVEtMtjGcsBVIdv08jb 2frn3H3oydmdA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B818D180068 for ; Fri, 6 Feb 2026 16:43:36 +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=0.6 required=5.0 tests=BAYES_50,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: No 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, 6 Feb 2026 16:43:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1770396209; bh=XWcHFSZO5j8PZ5IkfkmT1VhXUSATO1ipl6zeo5Z/qM4=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type:from:to:cc:subject:message-id; b=Zct07ngwv4rcIXtZB0CJmM1mK4019fYv3BxgZDVztdrMbplX1YVoWg7wNxeONARKt p0lVz6yYLSutMsg35w8k3JJqa1YhaTAe6Y3QzhyHYR7OPpidHScga5EoE8tbhc8wfa c91KLVkb9IH0IHM473jp6DnJLlINxu4BkiY4SdS6dvzNwYLCiRaiThw6B2YT+f8Smo vXsr9U6a3SFq8Q/iSs3dJp5febc0INXEpVgHeSncDS3yE0Nqs30+nyg35fesNOU34a XCXdzGyaM8ET2E/sSsnh/OVIC4EhMSbMorbbxOSuc0Bcc0gHp+Mb5frv3aMbpdVP/3 dSJtQ826wDKuA== Message-ID: <5c6ff4c3-8a1b-4b4a-8c1a-0acbb7b1cae2@bastelstu.be> Date: Fri, 6 Feb 2026 17:43:29 +0100 Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Subject: Re: [PHP-DEV] [RFC] Partial Function Application for instance of non-static methods ("$this") To: Larry Garfield , php internals References: <64953ec741a4c6609519e1878ad37b54@bastelstu.be> <253ee811-0c1d-7eab-4c36-38607401aaf6@php.net> <28461544eb11b41dce7c7563ad879e63@bastelstu.be> <62a90f31-697b-4607-a1ba-67956f5adfac@app.fastmail.com> Content-Language: en-US In-Reply-To: <62a90f31-697b-4607-a1ba-67956f5adfac@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 1/22/26 17:41, Larry Garfield wrote: > More spitballing on my previous reply: > > class Test { > public function stuff(int $a) {} > } > > (Test)?->stuff(?); As mentioned in the sibling mail, this is existing syntax and thus doesn't work. > But if there's no partialing on the method side, it could get abbreviated to: > > (?)->stuff(4); > > Translates to: > > fn(object $__this) => $__this->stuff(4); > > Because we don't need to know the type at compile time, and a method-not-found error would still happen at runtime anyway if necessary. By that argument you wouldn't need to type the argument as `object` either (calling methods on a non-object will throw) and the comparison would become: $c = (?)->stuff(4); $c = fn($o) => $o->stuff(4); Keeping full type information is the main benefit of PFA over “just write a Closure”. Being able to reorder parameters as part of partial application is another explicit feature that would not be supported by that syntax. > That would then be a lot easier to write in cases where you're just dropping a $this->stuff() call into a pipe chain but want to receive $this. The use case for partially applying `$this` is in cases where you need a “function handle”, that's why the examples are ones where the resulting Closure is passed as a parameter to another function. Within a pipe chain you would just use the regular `->` operator on the result of the previous step: $result = (trim($username) |> $repository->findBy(name: ?) )->getId(); It would also naturally support `?->` in case your repository returns `null` when the user cannot be found. Best regards Tim Düsterhus