[php-src] PR #25545: Fix GH-25380: Do not cache stateless closures with heap runtime cache

From: Date: Wed, 18 Nov 2026 04:02:17 +0000
Subject: [php-src] PR #25545: Fix GH-25380: Do not cache stateless closures with heap runtime cache
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-40762@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/25545 Author: prateekbhujel Closes GH-25380 ZEND_DECLARE_LAMBDA_FUNCTION caches stateless closures in EX(run_time_cache) via CACHE_POLYMORPHIC_PTR and pushes a reference onto EG(lambda_cache), which is only released at request shutdown. When the declaring function (EX(func)) has ZEND_ACC_HEAP_RT_CACHE (via Closure::bind()/bindTo() with a scope change, Closure::call(), or closures inside trait methods reused across multiple classes), its runtime cache is efree()d when the outer closure or call() finishes. Subsequent calls allocate a fresh zeroed runtime cache, miss CACHED_POLYMORPHIC_PTR, and push another unreachable closure onto EG(lambda_cache) for the rest of the request. Skip stateless closure caching when EX(func)->common.fn_flags & ZEND_ACC_HEAP_RT_CACHE is set. Because the check sits on the cache-miss write path (and heap runtime caches are zero-initialized), normal arena-cached ZEND_DECLARE_LAMBDA_FUNCTION cache hits pay no extra cost. Checked sibling caches as well: ZEND_CALLABLE_CONVERT (EG(callable_convert_cache)) and ZEND_CALLABLE_CONVERT_PARTIAL (EG(partial_function_application_cache)) deduplicate in request HashTables and already stay bounded across repeated Closure::bind() calls. ### Verification - Zend/tests/closures/: 139 passed, 1 skipped (zend_test) - Zend/tests/closures/gh25380.phpt: passed with both opcache.enable_cli=0 and opcache.enable_cli=1 - ext/opcache/tests/: 1027 passed, 46 skipped, 2 expected fail - Zend/tests/: 5562 passed, 178 skipped, 1 expected fail (new_oom.phpt only failed locally due to an unquoted space in the local workspace directory path)

« previous php.git-pulls (#40762) next »