From fe10ea1b20add257bae8352c06eeb2625088a0ba Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Fri, 6 Nov 2026 21:07:03 -0500 Subject: [PATCH] sapi/cli/php_cli.c: later -n and -c should supersede earlier ones The "-n" and "-c" flags serve essentially the same purpose, to indicate which ini file should be used. The -c flag lets you name an ini file explicitly, while -n means that no ini file should be used. Typically, argument parsers will override earlier occurrences of a flag with later ones. Later occurrences of -c do indeed override earlier -c flags, but if you specify -n after -c, the -n is essentially ignored; the ini file passed to -c is loaded anyway. After updating ext/standard/tests/ini_info/php_ini_loaded_file.phpt to support TEST_PHP_EXTRA_ARGS, that test fails if the extra args include -c. In particular, it fails "make test". This commit updates the argument parser so that subsequent -n override any existing -c flags, fixing the tests. --- ext/standard/tests/ini_info/php_ini_loaded_file.phpt | 2 +- sapi/cli/php_cli.c | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ext/standard/tests/ini_info/php_ini_loaded_file.phpt b/ext/standard/tests/ini_info/php_ini_loaded_file.phpt index 13217f028e02..89c603fca468 100644 --- a/ext/standard/tests/ini_info/php_ini_loaded_file.phpt +++ b/ext/standard/tests/ini_info/php_ini_loaded_file.phpt @@ -8,7 +8,7 @@ php_ini_loaded_file() function $code = '"var_dump(php_ini_loaded_file());"'; // No ini file ($args mays contains some) - passthru("$php -n -r $code"); + passthru("$php $args -n -r $code"); // Specified ini file passthru("$php $args -c $inifile -r $code"); diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c index fc62c0dd4b46..b7b0ae0f05e8 100644 --- a/sapi/cli/php_cli.c +++ b/sapi/cli/php_cli.c @@ -1266,12 +1266,19 @@ PHP_CLI_API int do_php_cli(int argc, char *argv[]) while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 1, 2))!=-1) { switch (c) { case 'c': + /* later -c override earlier -n */ + ini_ignore = 0; if (ini_path_override) { free(ini_path_override); } ini_path_override = strdup(php_optarg); break; case 'n': + /* later -n override earlier -c */ + if (ini_path_override) { + free(ini_path_override); + } + ini_path_override = NULL; ini_ignore = 1; break; case 'd':