Skip to content

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