From: Tyson Andre Date: Sun, 6 Sep 2020 13:43:09 +0000 (-0400) Subject: Improve handling of `#[` attributes in `php -a` X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1fc961e2de866ad426ce83dae760605599934673;p=php 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 Closes GH-6086 --- diff --git a/ext/readline/readline_cli.c b/ext/readline/readline_cli.c index d7e6f20c9f..2930796ae7 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 '/':