You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Observers reinitialized for closures defined in methods when OPcache is enabled #18546
@TimWolla That's to some degree expected behaviour, because without opcache the scope is changed on first usage of the closure. With opcache the scope is immutable.
And Closures have to allocate a different run_time_cache (which also causes an observer initialization).
There's no guarantee that observer is only initialized once for a given set of opcodes. The guarantee is once per run_time_cache.
For this specific case, we can however do if ((op_array->fn_flags & ZEND_ACC_STATIC) == 0) op_array->scope = CG(active_class_entry); for Closures in compiler - I think.
For this specific case, we can however do if ((op_array->fn_flags & ZEND_ACC_STATIC) == 0) op_array->scope = CG(active_class_entry); for Closures in compiler - I think.
Why limit it to non-static closures? static closures also have a scope and are affected by this issue. They just don't have $this, but can access private members of the surrounding class.
Activity
bwoebi commentedon May 13, 2025
@TimWolla That's to some degree expected behaviour, because without opcache the scope is changed on first usage of the closure. With opcache the scope is immutable.
And Closures have to allocate a different run_time_cache (which also causes an observer initialization).
There's no guarantee that observer is only initialized once for a given set of opcodes. The guarantee is once per run_time_cache.
For this specific case, we can however do
if ((op_array->fn_flags & ZEND_ACC_STATIC) == 0) op_array->scope = CG(active_class_entry);for Closures in compiler - I think.TimWolla commentedon May 14, 2025
Why limit it to non-static closures? static closures also have a scope and are affected by this issue. They just don't have
$this, but can accessprivatemembers of the surrounding class.And indeed:
seems to do the trick and seems to be a valid optimization for the assumption that most closures don't change their scope.
zend_compile: Set `op_array->scope` for Closures as compile time