From 5c0f515966fabef7d24ca774950982ef05cf3fef Mon Sep 17 00:00:00 2001 From: Pratik Bhujel Date: Wed, 9 Sep 2026 14:59:09 +0545 Subject: [PATCH] Fix GH-22214: Honor opcache.dups_fix for duplicate functions Check ignore_dups in _zend_accel_function_hash_copy before raising a redeclaration error, matching the existing behavior for classes. --- ext/opcache/tests/gh22214.phpt | 37 +++++++++++++++++++++++ ext/opcache/zend_accelerator_util_funcs.c | 8 ++++- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 ext/opcache/tests/gh22214.phpt diff --git a/ext/opcache/tests/gh22214.phpt b/ext/opcache/tests/gh22214.phpt new file mode 100644 index 000000000000..3dab39473180 --- /dev/null +++ b/ext/opcache/tests/gh22214.phpt @@ -0,0 +1,37 @@ +--TEST-- +GH-22214: opcache.dups_fix is honored for duplicate functions +--EXTENSIONS-- +opcache +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.file_update_protection=0 +opcache.dups_fix=1 +--FILE-- +hello(); +?> +--CLEAN-- + +--EXPECT-- +test_gh22214 called +TestGh22214 called diff --git a/ext/opcache/zend_accelerator_util_funcs.c b/ext/opcache/zend_accelerator_util_funcs.c index 2d2c693d0315..c2533076a905 100644 --- a/ext/opcache/zend_accelerator_util_funcs.c +++ b/ext/opcache/zend_accelerator_util_funcs.c @@ -159,7 +159,13 @@ static zend_always_inline void _zend_accel_function_hash_copy(HashTable *target, ZEND_ASSERT(p->key); t = zend_hash_find_known_hash(target, p->key); if (UNEXPECTED(t != NULL)) { - goto failure; + if (EXPECTED(ZSTR_LEN(p->key) > 0) && EXPECTED(ZSTR_VAL(p->key)[0] == 0)) { + /* Runtime definition key, keep old value */ + continue; + } else if (UNEXPECTED(!ZCG(accel_directives).ignore_dups)) { + goto failure; + } + continue; } _zend_hash_append_ptr_ex(target, p->key, Z_PTR(p->val), 1); if (UNEXPECTED(call_observers) && *ZSTR_VAL(p->key)) { // if not rtd key