[php-src] PR #26059: Fix GH-25919: Static var of cloned closure loses its reference

From: Date: Fri, 04 Dec 2026 07:04:46 +0000
Subject: [php-src] PR #26059: Fix GH-25919: Static var of cloned closure loses its reference
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-41407@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/26059 Author: Harp404 Fixes #25919. zend_create_closure_ex() copies a closure's static variables with zend_array_dup(), which unwraps references with a refcount of 1. Once a static variable's dynamic initializer (e.g. static $x = array_merge(...)) has run, its value is stored as such a reference, so the copy in a cloned or bindTo() closure holds the plain value. ZEND_BIND_INIT_STATIC_OR_JMP then asserted it was a reference and used it as one, which crashes (debug builds hit the assertion). The handler now wraps the value in a new reference when it is not one, the same way ZEND_BIND_STATIC handles static variables without a dynamic initializer. The clone keeps its own copy of the value, which the test checks along with the original closure. Targeting PHP-8.4 since it reproduces there. Zend/zend_vm_execute.h was regenerated with zend_vm_gen.php. I used Claude Code (Opus 5.5) to help investigate and draft this change; I reproduced the bug and checked the fix myself.

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