Skip to content

Improve handling of #[ attributes in php -a (finding end of statement) #6086

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

TysonAndre
Copy link
Contributor

a.k.a. "The handling of #[ in php -a is still terrible, are we sure we're OK with it?"

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'
php > echo "test"; # my comment
test
php > echo "test"; #
test

Followup to GH-6085

`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 phpGH-6085
@php-pulls php-pulls closed this in 1fc961e Sep 6, 2020
@TysonAndre TysonAndre deleted the attributes-readline branch November 25, 2021 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants