Improve handling of `#[` in `php -a`
authorTyson Andre <tysonandre775@hotmail.com>
Sat, 5 Sep 2020 20:52:14 +0000 (16:52 -0400)
committerTyson Andre <tysonandre775@hotmail.com>
Sat, 5 Sep 2020 21:33:20 +0000 (17:33 -0400)
PHP treats `#ini_setting=value` as a call to
`ini_set('ini_setting', 'value')`,
and silently skips undeclared settings.

This is a problem due to `#[` becoming supported attribute syntax:

- `#[Attr] const X = 123;` (this is not a valid place to put an attribute)
  This does not create a constant.
- `#[Attr] function test($x=false){}` also contains `=`.
  This does not create a function.

Instead, only treat lines starting with `#` as a special case
when the next character isn't `[`

Closes GH-6085

ext/readline/readline_cli.c

index a463a89db49416144db6e2dda364f29b34181b36..d7e6f20c9fbd8fbff70da87c680bef26251f7eea 100644 (file)
@@ -518,7 +518,7 @@ TODO:
        }
        if (text[0] == '$') {
                retval = cli_completion_generator_var(text, textlen, &cli_completion_state);
-       } else if (text[0] == '#') {
+       } else if (text[0] == '#' && text[1] != '[') {
                retval = cli_completion_generator_ini(text, textlen, &cli_completion_state);
        } else {
                char *lc_text, *class_name_end;
@@ -630,7 +630,7 @@ static int readline_shell_run(void) /* {{{ */
 
                len = strlen(line);
 
-               if (line[0] == '#') {
+               if (line[0] == '#' && line[1] != '[') {
                        char *param = strstr(&line[1], "=");
                        if (param) {
                                zend_string *cmd;