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