Skip to content

Commit 959e578

Browse files
committed
Disable -a mode without readline
To avoid confusing, as -a without readline is not actually interactive. Discussion: https://externals.io/message/114426 Closes GH-6976.
1 parent 840c78b commit 959e578

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

UPGRADING

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,12 @@ PHP 8.1 UPGRADE NOTES
277277
3. Changes in SAPI modules
278278
========================================
279279

280+
- CLI:
281+
. Using -a without the readline extension will now result in an error.
282+
Previously, -a without readline had the same behavior as calling php without
283+
any arguments, apart from printing an additional "Interactive mode enabled"
284+
message. This mode was not, in fact, interactive.
285+
280286
========================================
281287
4. Deprecated Functionality
282288
========================================

sapi/cli/php_cli.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -488,11 +488,7 @@ static void php_cli_usage(char *argv0)
488488
" %s [options] -- [args...]\n"
489489
" %s [options] -a\n"
490490
"\n"
491-
#if (defined(HAVE_LIBREADLINE) || defined(HAVE_LIBEDIT)) && !defined(COMPILE_DL_READLINE)
492-
" -a Run as interactive shell\n"
493-
#else
494-
" -a Run interactively\n"
495-
#endif
491+
" -a Run as interactive shell (requires readline extension)\n"
496492
" -c <path>|<file> Look for php.ini file in this directory\n"
497493
" -n No configuration (ini) files will be used\n"
498494
" -d foo[=bar] Define INI entry foo with value 'bar'\n"
@@ -694,6 +690,10 @@ static int do_cli(int argc, char **argv) /* {{{ */
694690
switch (c) {
695691

696692
case 'a': /* interactive mode */
693+
if (!cli_shell_callbacks.cli_shell_run) {
694+
param_error = "Interactive shell (-a) requires the readline extension.\n";
695+
break;
696+
}
697697
if (!interactive) {
698698
if (behavior != PHP_MODE_STANDARD) {
699699
param_error = param_mode_conflict;
@@ -874,13 +874,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
874874
#endif
875875

876876
if (interactive) {
877-
if (cli_shell_callbacks.cli_shell_run) {
878-
printf("Interactive shell\n\n");
879-
} else {
880-
printf("Interactive mode enabled\n\n");
881-
/* Treat as non-interactive apart from the stdin input */
882-
interactive = false;
883-
}
877+
printf("Interactive shell\n\n");
884878
fflush(stdout);
885879
}
886880

sapi/cli/tests/009.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
--TEST--
22
using invalid combinations of cmdline options
3+
--EXTENSIONS--
4+
readline
35
--SKIPIF--
46
<?php include "skipif.inc"; ?>
57
--FILE--

sapi/cli/tests/012-2.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
--TEST--
22
more invalid arguments and error messages
3+
--EXTENSIONS--
4+
readline
35
--SKIPIF--
46
<?php include "skipif.inc"; ?>
57
--FILE--

0 commit comments

Comments
 (0)