April 16, 2026
Keep $this out of it!
PHP 8.6 Closure Optimizations
Tiny functions get faster, but devs bicker over $this, identity, and “just use JS”
TLDR: PHP 8.6 plans to auto‑“freeze” certain tiny functions and reuse identical ones for small but real speed gains. Commenters cheered the free performance, argued about identity changes and $this confusion, and reignited PHP‑vs‑JS debates—because even 3% faster can still start a flame war.
PHP 8.6 wants to turbo‑charge “tiny functions” (closures) by auto‑marking them static when they don’t touch the object ($this) and by reusing identical, truly stateless ones. Translation: fewer throwaway clones, less memory waste, and a small but real speed bump—about ~3% in a Laravel test, with a synthetic benchmark flexing ~80%.
But the comments section? Pure chaos—and comedy. One camp cheers “free performance!” while another squints at the fine print: a few backward compatibility quirks (like tools seeing no object attached to some closures, and identical closures from the same spot now literally being the same instance). Cue the identity crisis memes. Who am I if two closures are one?
Confusion also took the stage. “~3% performance gains. I didn’t understand the part about $this,” admits one reader, giving the rest of the thread a chance to play explainer-in-chief: $this = “the current object.” If a closure doesn’t use it, PHP may freeze it as static and cache it—goodbye accidental memory handcuffs.
Then came the cross‑language drive‑by: “Why not just use JavaScript?” asked a veteran, reigniting the age‑old PHP vs JS skirmish. Another commenter compared JS’s behavior, noting it always makes new closure instances, which stoked fresh debate about identity vs speed. In classic internet fashion, the thread ends where it began: 3% faster, a little smarter, and a lot louder.
Key Points
- •PHP 8.6 RFC introduces two optimizations: static inference for closures not using $this, and caching of stateless closures.
- •Static inference avoids implicit $this captures that can create reference cycles and GC overhead.
- •Inference is constrained by rules (no $this, no $$var that could reference it, no potential hidden instance calls, no include/require/eval, etc.).
- •Benchmarks: ~78% of explicit static closures inferred in Symfony Demo; ~80% speedup in a synthetic test; ~3% gain in a Laravel template by avoiding 2,384/3,637 allocations.
- •BC changes: getClosureThis() may return NULL; stateless closures from the same site become identical; earlier collection may trigger destructors sooner; bind()/bindTo() behavior with static closures is clarified.