Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129859 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 9958F1A00BC for ; Thu, 22 Jan 2026 16:08:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1769098114; bh=U5ZqALIcId/AUEDah870o03FE6XNRBB/tWkShgumqio=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Dkgii8zPVuPDN08WIIzudjDFcuqhEmuGH3AOfkSI8tQl4/2wq2YBIo8ERS6MRPuAA aQceoHIdy8KDV08Q4VBhEWcoIA/+XnmSWi313BCrRmmXns01AMdv3C2Q6P5Ud8DuRv nRH7DdBThjRbPUXZRdFBhU3lnmkxfI40PSLf1h+9ZL6fBZoxFsdLkCOF780YIzRkoB gJzJmRizus2N4s/6RMCJKl9aUAwrK2k6gGS0aTD6Cisu5JzCC2RozQgrX+YPOd6J1Z weIRusGc5sfsQU6FVice5CnI4rvsIntfS40ln/O3upVupMQo7dGm31pC/iu+1M0KLa C5W8pbage2/jw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8EE36180705 for ; Thu, 22 Jan 2026 16:08:33 +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 ; Thu, 22 Jan 2026 16:08:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1769098102; bh=MYqOKtk1ujZ6rxQabBRSJQy9h0MUIqFP1mnVyJyXVbk=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type:from:to:cc:subject:message-id; b=BHG561UswlhGBmtsOMayBQOp9zdQ8dady+2s3reaNeSbJB+ll+7a4yto8lQpJXZax dUNBzqbHPTSqAdI7Hlg9GGFgH6TJMMOUHi6MDXJmJ/JszOwiKTTHbBSS9wsrB9Syn9 cdy4n4sO2rsBQPqrIA7Fq7S7uKTmYaEG5kVL2EkIKkaa8mIpUWtEAZTDw3UsIEr4BB ngh17HJu8Adl1SqzyMKKfldfOR3Ibq1nSfsPRnqC7VImJ9jXj/4FL8UDy5jckLImAf EUDXQyxGUgk2cqoGIm41+7JZirV6MxTCFV6OnKs9jmr3Ktf/RmXMz5G9LsXpFjPoIp cj9/uOuhe/fjg== Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Date: Thu, 22 Jan 2026 17:08:21 +0100 To: Derick Rethans Cc: php internals , Arnaud Le Blanc Subject: Re: [PHP-DEV] [RFC] Partial Function Application for instance of non-static methods ("$this") In-Reply-To: <253ee811-0c1d-7eab-4c36-38607401aaf6@php.net> References: <64953ec741a4c6609519e1878ad37b54@bastelstu.be> <253ee811-0c1d-7eab-4c36-38607401aaf6@php.net> Message-ID: <28461544eb11b41dce7c7563ad879e63@bastelstu.be> 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 Am 2026-01-22 16:33, schrieb Derick Rethans: >> https://wiki.php.net/rfc/partial_function_application_this > > We propose allowing a named parameter $this: ? to be combined with the > “scope resolution operator” syntax of referring to a method. > > I can't say I am entirely sold on the syntax here — starting with a $ > makes it look like a variable. Yes, it certainly requires some getting used to it. It's the best we could come up with, but if there are any better suggestions, we're open to hearing those. I'd like to note the “Rejected Features” section, since it lists some non-workable alternatives we considered. > Since the $this: ? parameter does not refer to a parameter in > the underlying argument list and thus there is no ambiguity with > regard to positional parameters it may be placed at any position > of the parameter list > > I think I would be keen on *requiring* this to be the **first** in the > argument list. > > Although there is no ambiguity, I also can't see why you would want to > have it anywhere else. Being able to “reorder” parameters to (better) fit a specific callback signature is an explicit feature of PFA that we also wanted to support for `$this`. As an example, suppose objects could be used as an array key. `array_find()` first passes the value and then the key to the callback. In this case users might want to do the following: class SomeObject { public function __construct(private string $value) { } public function hasMatchingValue(string $value) { return $value === $this->value; } } $array = [ new SomeObject('foo') => 'bar', new SomeObject('baz') => 'baz', ]; array_find(SomeObject::hasMatchingValue(value: ?, $this: ?), $array); In this case `array_find()` is supposed to return `'baz'`, since this is where the values match. > It may also not be used when partially applying an instance > method with a known object. > > $c = $dateTime->format($this: ?, "c"); // Fatal error: Invalid use of > $this placeholder > > Can you explain (in the RFC) what you mean by "known object" — I don't > think the language on what this means is clear enough. I have rephrased that to “It may also not be used when partially applying an instance method using the -> operator, since the object is already specified:” Best regards Tim Düsterhus