Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion main/php_variables.c
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an impossible branch. It's also dead code for the CLI.

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]);
}

Expand Down
8 changes: 7 additions & 1 deletion sapi/cli/php_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was intentionally removed, since the implementation just ignores the INI for the CLI entirely. In practice this will not hardcode the INI anyways, since the -d flag still takes precedence.


static const char SERVER_HARDCODED_INI[] =
"register_argc_argv=1\n";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CLI server is not the CLI.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was confused by this while keeping it hardcoded to On for CLI-related ones but the commit conveys a different message sapi: Remove hardcoded `register_argc_argv` for CLI SAPIs

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CLI server should not be treated as a CLI SAPI, since its purpose is HTTP requests. The CLI SAPIs are cli and phpdbg.


I was confused by this while keeping it hardcoded to On for CLI-related ones but the commit conveys a different message sapi: Remove hardcoded register_argc_argv for CLI SAPIs

Yes, the implementation does not actually match the RFC to the letter, but it matches it in intent. What the implementation does, is ignoring the INI setting when SG(request_info).arg is given, since that will match the actual argv given to the process and thus is trustworthy. This is only set for the CLI SAPIs.

So the RFC said "keeping it hardcoded to 1" and the implementation does "ignore the INI", which results in the same outcome, but a simpler and more predictable implementation. This is the relevant commit: 6ea0eb9

/cc @nicolas-grekas



const opt_struct OPTIONS[] = {
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions sapi/cli/tests/gh20279.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
GH-20279 (register_argc_argv set to off after deprecation.)
--SKIPIF--
<?php
include "skipif.inc";
?>
--FILE--
<?php
var_dump(ini_get("register_argc_argv"));
?>
--EXPECT--
string(1) "1"
29 changes: 29 additions & 0 deletions sapi/cli/tests/gh20279_server.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
GH-18582: Allow http_response_code() to clear HTTP start-line
--SKIPIF--
<?php
include "skipif.inc";
?>
--FILE--
<?php
include "php_cli_server.inc";
php_cli_server_start(<<<'PHP'
var_dump(ini_get("register_argc_argv"));
PHP);
$host = PHP_CLI_SERVER_HOSTNAME;
$fp = php_cli_server_connect();
if (fwrite($fp, "GET / HTTP/1.1\nHost: {$host}\n\n")) {
while (!feof($fp)) {
echo fgets($fp);
}
}
fclose($fp);
--EXPECTF--
HTTP/1.1 200 OK
Host: localhost
Date: %s
Connection: close
X-Powered-By: PHP/%s
Content-type: text/html; charset=UTF-8

string(1) "1"