Skip to content

Commit 1fc961e

Browse files
committed
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
1 parent 9439ca5 commit 1fc961e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

ext/readline/readline_cli.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ static int cli_is_valid_code(char *code, size_t len, zend_string **prompt) /* {{
250250
code_type = dstring;
251251
break;
252252
case '#':
253+
if (code[i+1] == '[') {
254+
valid_end = 0;
255+
break;
256+
}
253257
code_type = comment_line;
254258
break;
255259
case '/':

0 commit comments

Comments
 (0)