Skip to content
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

PHP7 "use" statement with curly braces throws Notice: Uninitialized string offset: 0 #23

Closed
drupalista-br opened this issue Dec 16, 2018 · 3 comments
Labels

Comments

@drupalista-br
Copy link

drupalista-br commented Dec 16, 2018

Declaring the "use" statements like below work just fine:

use App\SomeFolder\MyClass as Class1;
use App\SomeFolder\SomeSubfolder\MyClass as Class2;

Declaring them this way:

use App\SomeFolder\{
    MyClass as Class1,
    SomeSubfolder\MyClass as Class2,
};

Throws the following exception:

In ReflectionClosure.php line 779:
[ErrorException]
Notice: Uninitialized string offset: 0
Exception trace:
Opis\Closure\ReflectionClosure->fetchItems() at /my_project/vendor/opis/closure/src/ReflectionClosure.php:680
Opis\Closure\ReflectionClosure->getConstants() at /my_project/vendor/opis/closure/src/ReflectionClosure.php:472
Opis\Closure\ReflectionClosure->getCode() at /my_project/vendor/opis/closure/src/ReflectionClosure.php:559
Opis\Closure\ReflectionClosure->isBindingRequired() at /my_project/vendor/opis/closure/src/SerializableClosure.php:129
Opis\Closure\SerializableClosure->serialize() at n/a:n/a
serialize() at /my_project/src/my-script.php:41

@msarca
Copy link
Member

msarca commented Dec 16, 2018

This is because PHP 7.2 allow a trailing comma to the group-use. Removing the trailing comma after the Class2 will give you a quick fix for this.

use App\SomeFolder\{
    MyClass as Class1,
    SomeSubfolder\MyClass as Class2
};

@msarca msarca added the bug label Dec 16, 2018
@msarca
Copy link
Member

msarca commented Dec 16, 2018

Fixed in v3.1.2

@msarca msarca closed this as completed Dec 16, 2018
@drupalista-br
Copy link
Author

Thank you mate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants