Skip to content

Commit

Permalink
Disable -a mode without readline
Browse files Browse the repository at this point in the history
To avoid confusing, as -a without readline is not actually
interactive.

Discussion: https://externals.io/message/114426

Closes GH-6976.
  • Loading branch information
nikic committed May 14, 2021
1 parent 840c78b commit 959e578
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
6 changes: 6 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,12 @@ PHP 8.1 UPGRADE NOTES
3. Changes in SAPI modules
========================================

- CLI:
. Using -a without the readline extension will now result in an error.
Previously, -a without readline had the same behavior as calling php without
any arguments, apart from printing an additional "Interactive mode enabled"
message. This mode was not, in fact, interactive.

========================================
4. Deprecated Functionality
========================================
Expand Down
18 changes: 6 additions & 12 deletions sapi/cli/php_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,11 +488,7 @@ static void php_cli_usage(char *argv0)
" %s [options] -- [args...]\n"
" %s [options] -a\n"
"\n"
#if (defined(HAVE_LIBREADLINE) || defined(HAVE_LIBEDIT)) && !defined(COMPILE_DL_READLINE)
" -a Run as interactive shell\n"
#else
" -a Run interactively\n"
#endif
" -a Run as interactive shell (requires readline extension)\n"
" -c <path>|<file> Look for php.ini file in this directory\n"
" -n No configuration (ini) files will be used\n"
" -d foo[=bar] Define INI entry foo with value 'bar'\n"
Expand Down Expand Up @@ -694,6 +690,10 @@ static int do_cli(int argc, char **argv) /* {{{ */
switch (c) {

case 'a': /* interactive mode */
if (!cli_shell_callbacks.cli_shell_run) {
param_error = "Interactive shell (-a) requires the readline extension.\n";
break;
}
if (!interactive) {
if (behavior != PHP_MODE_STANDARD) {
param_error = param_mode_conflict;
Expand Down Expand Up @@ -874,13 +874,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
#endif

if (interactive) {
if (cli_shell_callbacks.cli_shell_run) {
printf("Interactive shell\n\n");
} else {
printf("Interactive mode enabled\n\n");
/* Treat as non-interactive apart from the stdin input */
interactive = false;
}
printf("Interactive shell\n\n");
fflush(stdout);
}

Expand Down
2 changes: 2 additions & 0 deletions sapi/cli/tests/009.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
--TEST--
using invalid combinations of cmdline options
--EXTENSIONS--
readline
--SKIPIF--
<?php include "skipif.inc"; ?>
--FILE--
Expand Down
2 changes: 2 additions & 0 deletions sapi/cli/tests/012-2.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
--TEST--
more invalid arguments and error messages
--EXTENSIONS--
readline
--SKIPIF--
<?php include "skipif.inc"; ?>
--FILE--
Expand Down

0 comments on commit 959e578

Please sign in to comment.