Conversation
…lled class The stateless closure cache in ZEND_DECLARE_LAMBDA_FUNCTION stored a single closure per opline. Since the declaring op_array is shared by all subclasses, the closure created for the first called scope was returned for every other called scope, breaking static::, new static() and get_called_class(). Store the called scope alongside the cached closure and only reuse the closure for a matching called scope. The slot is only filled once, as replacing the cached closure on a mismatch would grow EG(lambda_cache) without bounds. Fixes phpGH-23911 Signed-off-by: Roman Ondráček <mail@romanondracek.cz>
Roman3349
force-pushed
the
fix/gh-23911-static-closure-cache-called-scope
branch
from
October 5, 2026 19:30
7e7a0e6 to
c194f64
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes GH-23911
The stateless closure cache introduced in GH-23203 stores a single closure per
ZEND_DECLARE_LAMBDA_FUNCTIONopline. All subclasses share the declaringop_array, so the closure created for the first called scope was returned for
every other called scope. This broke
static::,new static()andget_called_class()inside static closures in inherited methods:The fix stores the called scope together with the cached closure (a two-slot
cache, like other polymorphic runtime caches) and only reuses the closure when
the called scope matches. The slot is only filled once. Replacing the cached
closure on a mismatch would push a new entry onto
EG(lambda_cache)each time,which is only freed at request shutdown, so alternating called scopes would
grow it without bounds. Other called scopes take the uncached path, which is
how every call behaved before 8.6.
The JIT does not compile this opcode (it calls the VM handler), so no JIT changes
are needed.