# [RFC][Discussion] Closure optimizations

- Thread: https://externals.io/message/129957
- Original archive: https://news-web.php.net/php.internals/129957
- Started by Ilija Tovilo on 2026-01-30T23:40:05+00:00
- Messages: 7
- RFC: Closure optimizations (Implemented (PHP 8.6)) — https://externals.io/rfc/closure-optimizations.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #129957 — Ilija Tovilo — 2026-01-30T23:40:05+00:00

URL: https://externals.io/message/129957#129957

Hi everyone

A week ago, I sent an e-mail to internals regarding two closure
optimizations with some subtle BC breaks. [1] While nobody objected, I
decided to create a short RFC anyway to avoid any possible controversy
due to the BC breaks. You can find it here:

https://wiki.php.net/rfc/closure-optimizations

Regards,
Ilija

[1] https://externals.io/message/129825

---

## #129958 — Claude Pache — 2026-01-31T01:31:19+00:00

URL: https://externals.io/message/129957#129958 · In reply to: #129957

> Le 31 janv. 2026 à 00:43, Ilija Tovilo <tovilo.ilija@gmail.com> a écrit :
> 
> ﻿Hi everyone
> 
> A week ago, I sent an e-mail to internals regarding two closure
> optimizations with some subtle BC breaks. [1] While nobody objected, I
> decided to create a short RFC anyway to avoid any possible controversy
> due to the BC breaks. You can find it here:
> 
> https://wiki.php.net/rfc/closure-optimizations
> 
> Regards,
> Ilija
> 
> [1] https://externals.io/message/129825

Hi,

The examples of the RFC all use the `function () { }` construct. I guess it does also apply to closures constructed with `fn() =>` ?

—Claude

---

## #129960 — Bob Weinand — 2026-01-31T03:59:16+00:00

URL: https://externals.io/message/129957#129960 · In reply to: #129957

Hey Ilija,


> Hi everyone
>
> A week ago, I sent an e-mail to internals regarding two closure
> optimizations with some subtle BC breaks. [1] While nobody objected, I
> decided to create a short RFC anyway to avoid any possible controversy
> due to the BC breaks. You can find it here:
>
> https://wiki.php.net/rfc/closure-optimizations
>
> Regards,
> Ilija
>
> [1]https://externals.io/message/129825

I'm a bit disappointed that you felt necessary to introduce bureaucracy 
for a straightforward very minor BC break. I don't like this something 
to become necessary or expected in future. Sending that email was 
completely sufficient.

I would like to encourage you to recognize that and simply merge your 
pull request.

Thanks,

Bob

---

## #129966 — Ilija Tovilo — 2026-01-31T16:32:48+00:00

URL: https://externals.io/message/129957#129966 · In reply to: #129960

Hi Bob


>
> 
>
> https://wiki.php.net/rfc/closure-optimizations
>
> I'm a bit disappointed that you felt necessary to introduce bureaucracy for a straightforward very minor BC break. I don't like this something to become necessary or expected in future. Sending that email was completely sufficient.
>
> I would like to encourage you to recognize that and simply merge your pull request.

I agree that the BC break is fairly minimal. What made me decide to
create an RFC after all is highlighted here:

> ReflectionFunction::getClosureThis() will now return `NULL` for closures that are inferred as static. This might be slightly surprising, given static inference does not work 100% reliably, limited by the rules previously described.

ReflectionFunction::getClosureThis() will work as long as the closure
uses $this, but it will also work if it calls static methods. Once you
remove the static call, it will break. Now, I don't think
ReflectionFunction::getClosureThis() is something many people rely on,
nor should they, but it is nonetheless surprising. I'd like to avoid
the situation where this is categorized as a bug that is effectively
impossible to solve without removing the optimization.

Ilija

---

## #129967 — Ilija Tovilo — 2026-01-31T16:35:44+00:00

URL: https://externals.io/message/129957#129967 · In reply to: #129958

Hi Claude


>
> > […]
>
> The examples of the RFC all use the `function () { }` construct. I guess it does also apply to closures constructed with `fn() =>` ?

Yes, the same applies to arrow functions. I clarified in the text and
added a short example.

Ilija

---

## #129969 — Jorg Sowa — 2026-01-31T17:54:23+00:00

URL: https://externals.io/message/129957#129969 · In reply to: #129957

Hi Ilija,

Thank you for this improvement. If I understand correctly, one of the
predicted BC changes will fix one of the issues with unit test comparisons.

The sebastianbergmann/comparator library cannot compare closures, because
each closure is in fact a different instance. With your change, this might
be resolved for static closures. So I see this is in fact very beneficial
for the unit testing.

https://github.com/sebastianbergmann/comparator/issues/129

Kind regards,
Jorg


On Sat, Jan 31, 2026 at 12:41 AM Ilija Tovilo <tovilo.ilija@gmail.com>
wrote:

> Hi everyone
>
> A week ago, I sent an e-mail to internals regarding two closure
> optimizations with some subtle BC breaks. [1] While nobody objected, I
> decided to create a short RFC anyway to avoid any possible controversy
> due to the BC breaks. You can find it here:
>
> https://wiki.php.net/rfc/closure-optimizations
>
> Regards,
> Ilija
>
> [1] https://externals.io/message/129825

---

## #130147 — Ilija Tovilo — 2026-02-24T01:21:06+00:00

URL: https://externals.io/message/129957#130147 · In reply to: #129957

Hi everyone


>
> https://wiki.php.net/rfc/closure-optimizations

Given there hasn't been any recent feedback or change to the RFC, I
intend to start the vote on Friday.

Ilija
