Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 58d8d94

Browse files
committed
Only quote php --ini values when out is a tty
A comment in #18527 mentioned that many scripts use `php—-ini` to bootstrap information about the system. Searching on GitHub confirms that many places will not work with quotes out of the box: https://github.com/search?q=content%3A%22php%20--ini%22&type=code. Many seem to be variants on this pattern ``` $ echo "extension=mongodb.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"` ``` To preserve these existing scripts, we can detect when the output is a TTY to optionally quote them. This is the new behavior: Output is a tty: ``` $ make -j$(nproc) &> /dev/null && env PHP_INI_SCAN_DIR="/opt/homebrew/etc/php/8.4/conf.d " PHPRC="/opt/homebrew/etc/php/8.4" ./sapi/cli/php --ini Configuration File (php.ini) Path: "/usr/local/lib" Loaded Configuration File: "/opt/homebrew/etc/php/8.4/php.ini" Scan for additional .ini files in: "/opt/homebrew/etc/php/8.4/conf.d " Additional .ini files parsed: (none) ``` Output is not a tty: ``` $ make -j$(nproc) &> /dev/null && env PHP_INI_SCAN_DIR="/opt/homebrew/etc/php/8.4/conf.d " PHPRC="/opt/homebrew/etc/php/8.4" ./sapi/cli/php --ini | tee Configuration File (php.ini) Path: /usr/local/lib Loaded Configuration File: /opt/homebrew/etc/php/8.4/php.ini Scan for additional .ini files in: /opt/homebrew/etc/php/8.4/conf.d Additional .ini files parsed: (none) ```
1 parent 419b9a7 commit 58d8d94

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

‎NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ PHP NEWS
1414
. Drop support for -z CLI/CGI flag. (nielsdos)
1515
. Fixed GH-17956 - development server 404 page does not adapt to mobiles.
1616
(pascalchevrel)
17+
. Changed `php --ini` to quotes some values with double quotes, to
18+
help humans debug unexpected whitespace, when stdout is a tty.
19+
(schneems)
1720

1821
- CURL:
1922
. Added CURLFOLLOW_ALL, CURLFOLLOW_OBEYCODE and CURLFOLLOW_FIRSTONLY

‎sapi/cli/php_cli.c

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,17 +1106,29 @@ static int do_cli(int argc, char **argv) /* {{{ */
11061106

11071107
case PHP_CLI_MODE_SHOW_INI_CONFIG:
11081108
{
1109-
zend_printf("Configuration File (php.ini) Path: \"%s\"\n", PHP_CONFIG_FILE_PATH);
1110-
if (php_ini_opened_path) {
1111-
zend_printf("Loaded Configuration File: \"%s\"\n", php_ini_opened_path);
1112-
} else {
1113-
zend_printf("Loaded Configuration File: (none)\n");
1114-
}
1115-
if (php_ini_scanned_path) {
1116-
zend_printf("Scan for additional .ini files in: \"%s\"\n", php_ini_scanned_path);
1117-
} else {
1118-
zend_printf("Scan for additional .ini files in: (none)\n");
1119-
}
1109+
int is_tty = 0;
1110+
#ifdef HAVE_UNISTD_H
1111+
is_tty = isatty(STDOUT_FILENO);
1112+
#elif defined(PHP_WIN32)
1113+
is_tty = php_win32_console_fileno_is_console(STDOUT_FILENO) && php_win32_console_fileno_has_vt100(STDOUT_FILENO);
1114+
#endif
1115+
char *quote = is_tty ? "\"" : "";
1116+
1117+
zend_printf("Configuration File (php.ini) Path: %s%s%s\n",
1118+
quote,
1119+
PHP_CONFIG_FILE_PATH,
1120+
quote
1121+
);
1122+
zend_printf("Loaded Configuration File: %s%s%s\n",
1123+
php_ini_opened_path ? quote : "",
1124+
php_ini_opened_path ? php_ini_opened_path : "(none)",
1125+
php_ini_opened_path ? quote : ""
1126+
);
1127+
zend_printf("Scan for additional .ini files in: %s%s%s\n",
1128+
php_ini_scanned_path ? quote : "",
1129+
php_ini_scanned_path ? php_ini_scanned_path : "(none)",
1130+
php_ini_scanned_path ? quote : ""
1131+
);
11201132
zend_printf("Additional .ini files parsed: %s\n", php_ini_scanned_files ? php_ini_scanned_files : "(none)");
11211133
break;
11221134
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /