From e3499130f1a9a1d9aa31d9763cb40e26394879c3 Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Thu, 11 May 2023 00:25:21 +0200 Subject: [PATCH] Fix delayed early binding class redeclaration error If we bind the class to the runtime slot even if we're not the ones who have performed early binding we'll miss the redeclaration error in the ZEND_DECLARE_CLASS_DELAYED handler. Closes GH-11226 --- NEWS | 1 + .../tests/delayed_early_binding_redeclaration-1.inc | 2 ++ .../tests/delayed_early_binding_redeclaration-2.inc | 2 ++ Zend/tests/delayed_early_binding_redeclaration.phpt | 13 +++++++++++++ ext/opcache/zend_accelerator_util_funcs.c | 6 +++--- 5 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 Zend/tests/delayed_early_binding_redeclaration-1.inc create mode 100644 Zend/tests/delayed_early_binding_redeclaration-2.inc create mode 100644 Zend/tests/delayed_early_binding_redeclaration.phpt diff --git a/NEWS b/NEWS index 48dfea01247..338c9723977 100644 --- a/NEWS +++ b/NEWS @@ -24,6 +24,7 @@ PHP NEWS - Opcache: . Fixed bug GH-11134 (Incorrect match default branch optimization). (ilutov) . Fixed too wide OR and AND range inference. (nielsdos) + . Fixed missing class redeclaration error with OPcache enabled. (ilutov) - PCNTL: . Fixed maximum argument count of pcntl_forkx(). (nielsdos) diff --git a/Zend/tests/delayed_early_binding_redeclaration-1.inc b/Zend/tests/delayed_early_binding_redeclaration-1.inc new file mode 100644 index 00000000000..abfccf90686 --- /dev/null +++ b/Zend/tests/delayed_early_binding_redeclaration-1.inc @@ -0,0 +1,2 @@ + +--EXPECTF-- +Fatal error: Cannot declare class Bar, because the name is already in use in %sdelayed_early_binding_redeclaration-2.inc on line %d diff --git a/ext/opcache/zend_accelerator_util_funcs.c b/ext/opcache/zend_accelerator_util_funcs.c index 9a64f92dab6..2ee60d4bbc4 100644 --- a/ext/opcache/zend_accelerator_util_funcs.c +++ b/ext/opcache/zend_accelerator_util_funcs.c @@ -358,9 +358,9 @@ static void zend_accel_do_delayed_early_binding( ce = zend_try_early_bind(orig_ce, parent_ce, early_binding->lcname, zv); } } - } - if (ce && early_binding->cache_slot != (uint32_t) -1) { - *(void**)((char*)run_time_cache + early_binding->cache_slot) = ce; + if (ce && early_binding->cache_slot != (uint32_t) -1) { + *(void**)((char*)run_time_cache + early_binding->cache_slot) = ce; + } } } CG(compiled_filename) = orig_compiled_filename;