diff --git a/ext/standard/tests/general_functions/bug43293_1.phpt b/ext/standard/tests/general_functions/bug43293_1.phpt index c1f618f2bd0e6..fce2ac482cd86 100644 --- a/ext/standard/tests/general_functions/bug43293_1.phpt +++ b/ext/standard/tests/general_functions/bug43293_1.phpt @@ -21,4 +21,5 @@ array(3) { [2]=> int(3) } -bool(false) +array(0) { +} diff --git a/main/php_variables.c b/main/php_variables.c index 91eb0a7f5ceac..b87f612ad3b5d 100644 --- a/main/php_variables.c +++ b/main/php_variables.c @@ -785,10 +785,13 @@ static void php_autoglobal_merge(HashTable *dest, HashTable *src) PHPAPI zend_result php_hash_environment(void) { memset(PG(http_globals), 0, sizeof(PG(http_globals))); + /* Register $argc and $argv for CLI SAPIs. $_SERVER['argc'] and $_SERVER['argv'] + * will be registered in php_auto_globals_create_server() which clears + * PG(http_globals)[TRACK_VARS_SERVER] anyways, making registration at this point + * useless. + */ + php_build_argv(NULL, NULL); zend_activate_auto_globals(); - if (PG(register_argc_argv)) { - php_build_argv(SG(request_info).query_string, &PG(http_globals)[TRACK_VARS_SERVER]); - } return SUCCESS; } /* }}} */ @@ -875,19 +878,18 @@ static bool php_auto_globals_create_server(zend_string *name) if (PG(variables_order) && (strchr(PG(variables_order),'S') || strchr(PG(variables_order),'s'))) { php_register_server_variables(); - if (PG(register_argc_argv)) { - if (SG(request_info).argc) { - zval *argc, *argv; + if (SG(request_info).argc) { + zval *argc, *argv; - if ((argc = zend_hash_find_ex_ind(&EG(symbol_table), ZSTR_KNOWN(ZEND_STR_ARGC), 1)) != NULL && - (argv = zend_hash_find_ex_ind(&EG(symbol_table), ZSTR_KNOWN(ZEND_STR_ARGV), 1)) != NULL) { - Z_ADDREF_P(argv); - zend_hash_update(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), ZSTR_KNOWN(ZEND_STR_ARGV), argv); - zend_hash_update(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), ZSTR_KNOWN(ZEND_STR_ARGC), argc); - } - } else { - php_build_argv(SG(request_info).query_string, &PG(http_globals)[TRACK_VARS_SERVER]); + if ((argc = zend_hash_find_ex_ind(&EG(symbol_table), ZSTR_KNOWN(ZEND_STR_ARGC), 1)) != NULL && + (argv = zend_hash_find_ex_ind(&EG(symbol_table), ZSTR_KNOWN(ZEND_STR_ARGV), 1)) != NULL) { + Z_ADDREF_P(argv); + zend_hash_update(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), ZSTR_KNOWN(ZEND_STR_ARGV), argv); + 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['argc'] and $_SERVER['argv'] from $_SERVER['QUERY_STRING'] is deprecated, configure register_argc_argv=0 to suppress this message and access the query parameters via $_SERVER['QUERY_STRING'] or $_GET"); + php_build_argv(SG(request_info).query_string, &PG(http_globals)[TRACK_VARS_SERVER]); } } else { diff --git a/php.ini-development b/php.ini-development index 6a217d30cb7ae..f8ceb6a3b7198 100644 --- a/php.ini-development +++ b/php.ini-development @@ -662,7 +662,7 @@ request_order = "GP" ; enabled, registering these variables consumes CPU cycles and memory each time ; a script is executed. For security reasons, this feature should be disabled ; for non-CLI SAPIs. -; Note: This directive is hardcoded to On for the CLI SAPI +; Note: This directive is ignored for the CLI SAPI ; This directive is deprecated. ; https://php.net/register-argc-argv ;register_argc_argv = Off diff --git a/php.ini-production b/php.ini-production index 09c048a1efe25..236b6bb0b2f1d 100644 --- a/php.ini-production +++ b/php.ini-production @@ -664,7 +664,7 @@ request_order = "GP" ; enabled, registering these variables consumes CPU cycles and memory each time ; a script is executed. For security reasons, this feature should be disabled ; for non-CLI SAPIs. -; Note: This directive is hardcoded to On for the CLI SAPI +; Note: This directive is ignored for the CLI SAPI ; This directive is deprecated. ; https://php.net/register-argc-argv ;register_argc_argv = Off diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c index e212a0f71a23d..460acb62664a6 100644 --- a/sapi/cli/php_cli.c +++ b/sapi/cli/php_cli.c @@ -115,7 +115,6 @@ PHP_CLI_API cli_shell_callbacks_t *php_cli_get_shell_callbacks(void) static const char HARDCODED_INI[] = "html_errors=0\n" - "register_argc_argv=1\n" "implicit_flush=1\n" "output_buffering=0\n" "max_execution_time=0\n" diff --git a/sapi/embed/php_embed.c b/sapi/embed/php_embed.c index c18480d07d313..06cd1fb0763b7 100644 --- a/sapi/embed/php_embed.c +++ b/sapi/embed/php_embed.c @@ -25,7 +25,6 @@ static const char HARDCODED_INI[] = "html_errors=0\n" - "register_argc_argv=1\n" "implicit_flush=1\n" "output_buffering=0\n" "max_execution_time=0\n" diff --git a/sapi/fpm/tests/bug75712-getenv-server-vars_001.phpt b/sapi/fpm/tests/bug75712-getenv-server-vars_001.phpt new file mode 100644 index 0000000000000..c81cdf8f6d2fd --- /dev/null +++ b/sapi/fpm/tests/bug75712-getenv-server-vars_001.phpt @@ -0,0 +1,68 @@ +--TEST-- +FPM: bug75712 - getenv should not read from $_ENV and $_SERVER +--SKIPIF-- + +--FILE-- +start(); +$tester->expectLogStartNotices(); +$response = $tester->request(); +echo "=====", PHP_EOL; +$response->printBody(); +echo "=====", PHP_EOL; +$tester->terminate(); +$tester->close(); + +?> +Done +--EXPECTF-- +===== +Deprecated: Deriving $_SERVER['argc'] and $_SERVER['argv'] from $_SERVER['QUERY_STRING'] is deprecated, configure register_argc_argv=0 to suppress this message and access the query parameters via $_SERVER['QUERY_STRING'] or $_GET in %s on line %d +bool(false) +bool(true) +string(4) "test" +bool(false) +bool(false) +string(2) "dt" +string(2) "dt" +===== +Done +--CLEAN-- + diff --git a/sapi/fpm/tests/bug75712-getenv-server-vars.phpt b/sapi/fpm/tests/bug75712-getenv-server-vars_002.phpt similarity index 88% rename from sapi/fpm/tests/bug75712-getenv-server-vars.phpt rename to sapi/fpm/tests/bug75712-getenv-server-vars_002.phpt index 49d9535a6b03a..b34d936eaf223 100644 --- a/sapi/fpm/tests/bug75712-getenv-server-vars.phpt +++ b/sapi/fpm/tests/bug75712-getenv-server-vars_002.phpt @@ -1,5 +1,5 @@ --TEST-- -FPM: bug75712 - getenv should not read from $_ENV and $_SERVER +FPM: bug75712 - getenv should not read from $_ENV and $_SERVER (register_argc_argv=off) --SKIPIF-- --FILE-- @@ -15,7 +15,7 @@ listen = {{ADDR}} pm = static pm.max_children = 1 env[TEST] = test -php_value[register_argc_argv] = on +php_value[register_argc_argv] = off EOT; $code = << ---EXPECT-- +--EXPECTF-- +Deprecated: Deriving $_SERVER['argc'] and $_SERVER['argv'] from $_SERVER['QUERY_STRING'] is deprecated, configure register_argc_argv=0 to suppress this message and access the query parameters via $_SERVER['QUERY_STRING'] or $_GET in %s on line %d 0: ab 1: cd 2: ef diff --git a/tests/basic/011_empty_query.phpt b/tests/basic/011_empty_query.phpt new file mode 100644 index 0000000000000..041b779cf2193 --- /dev/null +++ b/tests/basic/011_empty_query.phpt @@ -0,0 +1,20 @@ +--TEST-- +Testing $argc and $argv handling (GET empty) +--SKIPIF-- + +--INI-- +register_argc_argv=1 +--CGI-- +--FILE-- + +--EXPECTF-- +Deprecated: Deriving $_SERVER['argc'] and $_SERVER['argv'] from $_SERVER['QUERY_STRING'] is deprecated, configure register_argc_argv=0 to suppress this message and access the query parameters via $_SERVER['QUERY_STRING'] or $_GET in %s on line %d +int(0) +array(0) { +} diff --git a/tests/basic/011_register_argc_argv_disabled.phpt b/tests/basic/011_register_argc_argv_disabled.phpt new file mode 100644 index 0000000000000..0947a911dd0ff --- /dev/null +++ b/tests/basic/011_register_argc_argv_disabled.phpt @@ -0,0 +1,22 @@ +--TEST-- +Testing $argc and $argv handling (GET, register_argc_argv=0) +--SKIPIF-- + +--INI-- +register_argc_argv=0 +--GET-- +ab+cd+ef+123+test +--FILE-- + +--EXPECTF-- +Warning: Undefined array key "argc" in %s on line %d + +Warning: Undefined array key "argv" in %s on line %d +NULL +NULL diff --git a/tests/basic/011_windows.phpt b/tests/basic/011_windows.phpt index fd359fe4032af..6049e4d2416c0 100644 --- a/tests/basic/011_windows.phpt +++ b/tests/basic/011_windows.phpt @@ -14,7 +14,8 @@ for ($i=0; $i<$argc; $i++) { } ?> ---EXPECT-- +--EXPECTF-- +Deprecated: Deriving $_SERVER['argc'] and $_SERVER['argv'] from $_SERVER['QUERY_STRING'] is deprecated, configure register_argc_argv=0 to suppress this message and access the query parameters via $_SERVER['QUERY_STRING'] or $_GET in %s on line %d 0: foo=ab 1: cd 2: ef diff --git a/tests/basic/012_register_argc_argv_disabled.phpt b/tests/basic/012_register_argc_argv_disabled.phpt new file mode 100644 index 0000000000000..415e39074f3b6 --- /dev/null +++ b/tests/basic/012_register_argc_argv_disabled.phpt @@ -0,0 +1,49 @@ +--TEST-- +Testing $argc and $argv handling (cli, register_argc_argv=0) +--INI-- +register_argc_argv=0 +variables_order=GPS +--ARGS-- +ab cd ef 123 test +--FILE-- + +--EXPECTF-- +int(6) +array(6) { + [0]=> + string(%d) "%s" + [1]=> + string(2) "ab" + [2]=> + string(2) "cd" + [3]=> + string(2) "ef" + [4]=> + string(3) "123" + [5]=> + string(4) "test" +} +int(6) +array(6) { + [0]=> + string(%d) "%s" + [1]=> + string(2) "ab" + [2]=> + string(2) "cd" + [3]=> + string(2) "ef" + [4]=> + string(3) "123" + [5]=> + string(4) "test" +}