From 8b51bcaa18a754a695dc2f8654f0e70c5d822a7b Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Thu, 18 Sep 2025 11:57:38 +0200 Subject: [PATCH] Fix CGI with auto_globals_jit=0 In CGI, php_auto_globals_create_server() (i.e. auto_global_callback() here) initializes $_ENV to reuse for $_SERVER. However, because $_SERVER is constructed first, we have not yet initialized auto_global->armed of the $_ENV global. Split the loop into initialization and constructor phases. Closes GH-19870 --- Zend/zend_compile.c | 10 +++++----- sapi/cgi/tests/auto_globals_no_jit.phpt | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 sapi/cgi/tests/auto_globals_no_jit.phpt diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index ce4b4e3b7fd..2eee6a01caf 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -2014,12 +2014,12 @@ ZEND_API void zend_activate_auto_globals(void) /* {{{ */ zend_auto_global *auto_global; ZEND_HASH_MAP_FOREACH_PTR(CG(auto_globals), auto_global) { - if (auto_global->jit) { - auto_global->armed = 1; - } else if (auto_global->auto_global_callback) { + auto_global->armed = auto_global->jit || auto_global->auto_global_callback; + } ZEND_HASH_FOREACH_END(); + + ZEND_HASH_MAP_FOREACH_PTR(CG(auto_globals), auto_global) { + if (auto_global->armed && !auto_global->jit) { auto_global->armed = auto_global->auto_global_callback(auto_global->name); - } else { - auto_global->armed = 0; } } ZEND_HASH_FOREACH_END(); } diff --git a/sapi/cgi/tests/auto_globals_no_jit.phpt b/sapi/cgi/tests/auto_globals_no_jit.phpt new file mode 100644 index 00000000000..e331709db6d --- /dev/null +++ b/sapi/cgi/tests/auto_globals_no_jit.phpt @@ -0,0 +1,17 @@ +--TEST-- +CGI with auto_globals_jit=0 +--INI-- +auto_globals_jit=0 +--CGI-- +--ENV-- +FOO=BAR +--FILE-- + +--EXPECT-- +string(3) "BAR" +string(3) "BAR" +string(3) "BAR"