On Thu, January 22, 2026 at 03:50 Tim Düsterhus wrote:

> Arnaud and I would like to start discussion on our RFC “Partial Function
> Application for instance of non-static methods ("$this")” which is
> intended to round-off the Partial Function Application RFC that was
> accepted recently:
>
> https://wiki.php.net/rfc/partial_function_application_this

Hi Tim and Arnaud,

Thank you for your work on this. However, I'm struggling to see the benefit
of this syntax over short closures given the examples in the RFC:

    $dates = [
        new DateTimeImmutable('now'),
    ];

    $formattedDates = array_map(DateTimeImmutable::format($this: ?, "c"), 
$dates);

This saves only three characters compared to a short closure:

    $formattedDates = array_map(fn(DateTimeImmutable $d) => $d->format("c"), 
$dates);

Furthermore, duplicating the array's type isn't necessary when IDEs and static
analysis can infer it, so short closures can usually be even more concise:

    $formattedDates = array_map(fn($d) => $d->format("c"), $dates);


I also find the use of `$this` as a named argument confusing. It makes it
appear as though the current class instance is somehow being passed to the
method, when this isn't the case.


The other example with Symfony Form's `ChoiceType` doesn't sell the syntax
for me, either:

    'choice_label' => Category::getName($this: ?),

A short closure is barely any longer, and makes it easier to add additional
logic when needed:

    'choice_label' => fn(Category $c) => $c->getName(),

    'choice_label' => fn(Category $c) => strtoupper($c->getName()),


Ultimately I'm not convinced it's worth it to make the partial function syntax
and semantics more complicated to support this scenario, given that short
closures already provide similar conciseness and greater flexibility.

Kind regards,  
Theodore

Reply via email to