From 289f27e70bb30cdf5038fbd7ab0768bc2cf32062 Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Thu, 15 Sep 2022 20:56:43 +0200 Subject: [PATCH] Fix class link observer with file_cache_only=1 Previously, notify would only get called on classes with CE_CACHE. However, during compilation class names are non-permanent which won't get a CE_CACHE and thus wouldn't not get notified. --- ext/opcache/zend_accelerator_util_funcs.c | 8 +++---- .../observer_declarations_file_cache.phpt | 23 +++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 ext/zend_test/tests/observer_declarations_file_cache.phpt diff --git a/ext/opcache/zend_accelerator_util_funcs.c b/ext/opcache/zend_accelerator_util_funcs.c index aab83bce4ecfc..9a64f92dab6ee 100644 --- a/ext/opcache/zend_accelerator_util_funcs.c +++ b/ext/opcache/zend_accelerator_util_funcs.c @@ -232,10 +232,10 @@ static zend_always_inline void _zend_accel_class_hash_copy(HashTable *target, Ha } else { zend_class_entry *ce = Z_PTR(p->val); _zend_hash_append_ptr_ex(target, p->key, Z_PTR(p->val), 1); - if ((ce->ce_flags & ZEND_ACC_LINKED) - && ZSTR_HAS_CE_CACHE(ce->name) - && ZSTR_VAL(p->key)[0]) { - ZSTR_SET_CE_CACHE_EX(ce->name, ce, 0); + if ((ce->ce_flags & ZEND_ACC_LINKED) && ZSTR_VAL(p->key)[0]) { + if (ZSTR_HAS_CE_CACHE(ce->name)) { + ZSTR_SET_CE_CACHE_EX(ce->name, ce, 0); + } if (UNEXPECTED(call_observers)) { _zend_observer_class_linked_notify(ce, p->key); } diff --git a/ext/zend_test/tests/observer_declarations_file_cache.phpt b/ext/zend_test/tests/observer_declarations_file_cache.phpt new file mode 100644 index 0000000000000..df20e359c0e58 --- /dev/null +++ b/ext/zend_test/tests/observer_declarations_file_cache.phpt @@ -0,0 +1,23 @@ +--TEST-- +Observer: Observe function and class declarations with file_cache_only +--EXTENSIONS-- +zend_test +--INI-- +zend_test.observer.enabled=1 +zend_test.observer.observe_declaring=1 +opcache.enable_cli=1 +opcache.file_cache={TMP} +opcache.file_cache_only=1 +--FILE-- + +--EXPECTF-- + + + +