Skip to content

Commit 6622c54

Browse files
committed
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. Closes GH-9550
1 parent dbbb742 commit 6622c54

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.2.0RC3
44

5+
- Core:
6+
. Fixed observer class notify with Opcache file_cache_only=1. (ilutov)
7+
58
- Date:
69
. Fixed bug with parsing large negative numbers with the @ notation. (Derick)
710

ext/opcache/zend_accelerator_util_funcs.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,10 @@ static zend_always_inline void _zend_accel_class_hash_copy(HashTable *target, Ha
232232
} else {
233233
zend_class_entry *ce = Z_PTR(p->val);
234234
_zend_hash_append_ptr_ex(target, p->key, Z_PTR(p->val), 1);
235-
if ((ce->ce_flags & ZEND_ACC_LINKED)
236-
&& ZSTR_HAS_CE_CACHE(ce->name)
237-
&& ZSTR_VAL(p->key)[0]) {
238-
ZSTR_SET_CE_CACHE_EX(ce->name, ce, 0);
235+
if ((ce->ce_flags & ZEND_ACC_LINKED) && ZSTR_VAL(p->key)[0]) {
236+
if (ZSTR_HAS_CE_CACHE(ce->name)) {
237+
ZSTR_SET_CE_CACHE_EX(ce->name, ce, 0);
238+
}
239239
if (UNEXPECTED(call_observers)) {
240240
_zend_observer_class_linked_notify(ce, p->key);
241241
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Observer: Observe function and class declarations with file_cache_only
3+
--EXTENSIONS--
4+
zend_test
5+
--INI--
6+
zend_test.observer.enabled=1
7+
zend_test.observer.observe_declaring=1
8+
opcache.enable_cli=1
9+
opcache.file_cache={TMP}
10+
opcache.file_cache_only=1
11+
--FILE--
12+
<?php
13+
14+
function a() {}
15+
class A {}
16+
class B extends A {}
17+
18+
?>
19+
--EXPECTF--
20+
<!-- declared function 'a' -->
21+
<!-- declared class 'a' -->
22+
<!-- declared class 'b' -->
23+
<!-- init '%s' -->

0 commit comments

Comments
 (0)