Skip to content

Commit

Permalink
Improve handling of #[ attributes in php -a
Browse files Browse the repository at this point in the history
`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
  • Loading branch information
TysonAndre committed Sep 6, 2020
1 parent 9439ca5 commit 1fc961e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ext/readline/readline_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 '/':
Expand Down

0 comments on commit 1fc961e

Please sign in to comment.