From 8b748e2907c9009515ae0995177649cfef9f0b61 Mon Sep 17 00:00:00 2001 From: Tyson Andre Date: Sun, 6 Sep 2020 09:43:09 -0400 Subject: [PATCH] Improve handling of `#[` attributes in `php -a` `php -a` treats lines starting with `#` as comments when deciding if the provided statement is valid. So it passed `#[MyAttr]` to the parser after the user hits enter, causing a syntax error for multi-line statements.. With this patch, the following snippet is parsed correctly ``` php > #[Attr] php > function x() { } php > var_export((new ReflectionFunction('x'))->getAttributes()[0]->getName()); 'Attr' ``` Followup to GH-6085 --- ext/readline/readline_cli.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ext/readline/readline_cli.c b/ext/readline/readline_cli.c index d7e6f20c9fbd8..2930796ae7605 100644 --- a/ext/readline/readline_cli.c +++ b/ext/readline/readline_cli.c @@ -250,6 +250,10 @@ static int cli_is_valid_code(char *code, size_t len, zend_string **prompt) /* {{ code_type = dstring; break; case '#': + if (code[i+1] == '[') { + valid_end = 0; + break; + } code_type = comment_line; break; case '/':