[PHP-DEV] [Vote] Closure optimizations

Hi everyone

As foreshadowed, I opened the vote for the closure optimizations RFC.

RFC: PHP: rfc:closure-optimizations
PR: Infer static for closures by iluuu1994 · Pull Request #19941 · php/php-src · GitHub
Discussion: php.internals: [RFC][Discussion] Closure optimizations
Original announcement: php.internals: Closure optimizations

The vote will end on 2026-03-13 14:00 UTC.

Ilija

On Fri, 27 Feb 2026 at 13:47, Ilija Tovilo <tovilo.ilija@gmail.com> wrote:

Hi everyone

As foreshadowed, I opened the vote for the closure optimizations RFC.

RFC: PHP: rfc:closure-optimizations
PR: Infer static for closures by iluuu1994 · Pull Request #19941 · php/php-src · GitHub
Discussion: php.internals: [RFC][Discussion] Closure optimizations
Original announcement: php.internals: Closure optimizations

The vote will end on 2026-03-13 14:00 UTC.

Ilija

Is there any benefit for projects that already mark all static
closures with the keyword "static"?
One thing I am worried about is that people may think the RFC removes
the need for that keyword, which it looks like it doesn't. Not only
can your patch not infer 100% of static closures, but it also doesn't
prevent accidentally using $this in a closure that was supposed to be
static.

Hi Kamil

On Fri, Feb 27, 2026 at 3:16 PM Kamil Tekiela <tekiela246@gmail.com> wrote:

On Fri, 27 Feb 2026 at 13:47, Ilija Tovilo <tovilo.ilija@gmail.com> wrote:
>
> As foreshadowed, I opened the vote for the closure optimizations RFC.
>
> RFC: PHP: rfc:closure-optimizations

Is there any benefit for projects that already mark all static
closures with the keyword "static"?

Yes. The caching of stateless closures is what brings most of the
performance benefits. Static closure inference enables this
optimization in more cases, namely in codebases that don't explicitly
want to add static for whatever reason.

One thing I am worried about is that people may think the RFC removes
the need for that keyword, which it looks like it doesn't. Not only
can your patch not infer 100% of static closures, but it also doesn't
prevent accidentally using $this in a closure that was supposed to be
static.

The RFC is explicit about static not being redundant.

While explicit marking remains preferable, this optimization aims to benefit codebases that prefer not to add static to avoid visual clutter, as well as those who aren't aware of these subtle performance implications.

Ilija