From 22dc7217f16a0acd931c5905790fc347ad0c453e Mon Sep 17 00:00:00 2001 From: David Carlier Date: Fri, 24 Oct 2025 14:35:46 +0100 Subject: [PATCH 1/2] Fix GH-20279: register_argc_argv set at 0 on sapi cli after deprecation. --- main/php_variables.c | 4 +++- sapi/cli/php_cli.c | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/main/php_variables.c b/main/php_variables.c index 971e1c77ea9f4..d5fec5ee9ac47 100644 --- a/main/php_variables.c +++ b/main/php_variables.c @@ -888,7 +888,9 @@ static bool php_auto_globals_create_server(zend_string *name) zend_hash_update(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), ZSTR_KNOWN(ZEND_STR_ARGC), argc); } } else if (PG(register_argc_argv)) { - zend_error(E_DEPRECATED, "Deriving $_SERVER['argv'] from the query string is deprecated. Configure register_argc_argv=0 to turn this message off"); + if (strcmp(sapi_module.name, "cli") && strcmp(sapi_module.name, "cli-server")) { + zend_error(E_DEPRECATED, "Deriving $_SERVER['argv'] from the query string is deprecated. Configure register_argc_argv=0 to turn this message off"); + } php_build_argv(SG(request_info).query_string, &PG(http_globals)[TRACK_VARS_SERVER]); } diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c index 460acb62664a6..485ac5e245dab 100644 --- a/sapi/cli/php_cli.c +++ b/sapi/cli/php_cli.c @@ -118,7 +118,11 @@ static const char HARDCODED_INI[] = "implicit_flush=1\n" "output_buffering=0\n" "max_execution_time=0\n" - "max_input_time=-1\n"; + "max_input_time=-1\n" + "register_argc_argv=1\n"; + +static const char SERVER_HARDCODED_INI[] = + "register_argc_argv=1\n"; const opt_struct OPTIONS[] = { @@ -1321,6 +1325,8 @@ int main(int argc, char *argv[]) if (sapi_module_ptr == &cli_sapi_module) { php_ini_builder_prepend_literal(&ini_builder, HARDCODED_INI); + } else { + php_ini_builder_prepend_literal(&ini_builder, SERVER_HARDCODED_INI); } sapi_module_ptr->ini_entries = php_ini_builder_finish(&ini_builder); From 05730552a103f9b20724be78887a7bdccc217645 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Fri, 24 Oct 2025 15:23:54 +0100 Subject: [PATCH 2/2] add tests --- sapi/cli/tests/gh20279.phpt | 12 ++++++++++++ sapi/cli/tests/gh20279_server.phpt | 29 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 sapi/cli/tests/gh20279.phpt create mode 100644 sapi/cli/tests/gh20279_server.phpt diff --git a/sapi/cli/tests/gh20279.phpt b/sapi/cli/tests/gh20279.phpt new file mode 100644 index 0000000000000..5b9b304c5b904 --- /dev/null +++ b/sapi/cli/tests/gh20279.phpt @@ -0,0 +1,12 @@ +--TEST-- +GH-20279 (register_argc_argv set to off after deprecation.) +--SKIPIF-- + +--FILE-- + +--EXPECT-- +string(1) "1" diff --git a/sapi/cli/tests/gh20279_server.phpt b/sapi/cli/tests/gh20279_server.phpt new file mode 100644 index 0000000000000..4d3e0cabeb3d9 --- /dev/null +++ b/sapi/cli/tests/gh20279_server.phpt @@ -0,0 +1,29 @@ +--TEST-- +GH-18582: Allow http_response_code() to clear HTTP start-line +--SKIPIF-- + +--FILE-- +