psysh: Parse errors when using namespaced classes/functions
I’m getting this really weird bug, since I’ve upgraded my Laravel version to 7.x (Laravel Tinker v2.4.2). The shell doesn’t accept me using FQCNs anymore. See the output below:
Psy Shell v0.10.4 (PHP 7.3.20-1+ubuntu18.04.1+deb.sury.org+1 — cli) by Justin Hileman
>>> User::class
=> "User"
>>> \App\User::class
PHP Parse error: Syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM on line 1
>>> namespace App;
>>> User::class
=> "App\User"
>>> App\User::class
PHP Parse error: Syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM on line 1
>>> \App\User::class
PHP Parse error: Syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM on line 1
>>> wtf -a
PHP Parse error: Syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM on line 1
--
0: () at vendor/psy/psysh/src/Exception/ParseErrorException.php:40
1: Psy\Exception\ParseErrorException::fromParseError() at vendor/psy/psysh/src/CodeCleaner.php:294
2: Psy\CodeCleaner->parse() at vendor/psy/psysh/src/CodeCleaner.php:221
3: Psy\CodeCleaner->clean() at vendor/psy/psysh/src/Shell.php:829
4: Psy\Shell->addCode() at vendor/psy/psysh/src/Shell.php:521
5: Psy\Shell->getInput() at vendor/psy/psysh/src/ExecutionLoopClosure.php:40
6: Psy\{closure}() at vendor/psy/psysh/src/ExecutionClosure.php:96
7: Psy\ExecutionClosure->execute() at vendor/psy/psysh/src/Shell.php:370
8: Psy\Shell->doInteractiveRun() at vendor/psy/psysh/src/Shell.php:341
9: Psy\Shell->doRun() at vendor/symfony/console/Application.php:140
10: Symfony\Component\Console\Application->run() at vendor/psy/psysh/src/Shell.php:316
11: Psy\Shell->run() at vendor/laravel/tinker/src/Console/TinkerCommand.php:81
12: Laravel\Tinker\Console\TinkerCommand->handle() at n/a:n/a
13: call_user_func_array() at vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:37
14: Illuminate\Container\BoundMethod::Illuminate\Container\{closure}() at vendor/laravel/framework/src/Illuminate/Container/Util.php:37
15: Illuminate\Container\Util::unwrapIfClosure() at vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:95
16: Illuminate\Container\BoundMethod::callBoundMethod() at vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:39
17: Illuminate\Container\BoundMethod::call() at vendor/laravel/framework/src/Illuminate/Container/Container.php:596
18: Illuminate\Container\Container->call() at vendor/laravel/framework/src/Illuminate/Console/Command.php:134
19: Illuminate\Console\Command->execute() at vendor/symfony/console/Command/Command.php:258
20: Symfony\Component\Console\Command\Command->run() at vendor/laravel/framework/src/Illuminate/Console/Command.php:121
21: Illuminate\Console\Command->run() at vendor/symfony/console/Application.php:916
22: Symfony\Component\Console\Application->doRunCommand() at vendor/symfony/console/Application.php:264
23: Symfony\Component\Console\Application->doRun() at vendor/symfony/console/Application.php:140
24: Symfony\Component\Console\Application->run() at vendor/laravel/framework/src/Illuminate/Console/Application.php:93
25: Illuminate\Console\Application->run() at vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:129
26: Illuminate\Foundation\Console\Kernel->handle() at artisan:38
Even running psy\info() doesn’t work:
>>> psy\info()
PHP Parse error: Syntax error, unexpected ')' on line 1
I get the same error locally, in a docker container and on our server. I have no config files for psysh, but maybe Laravel adds some configuration through Tinker out of the box.
Do you have any idea how I can fix this?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 24 (11 by maintainers)
Sadly, the same result:
It’s really weird you can’t reproduce the issue. Of course we have a ton of code and external dependencies, so those could also influence the code. For now I have a solution: use
v3.*ofphp-parser. Thanks a lot for your time and help!Thanks for checking @ikari7789! I was already on
v4.9.1ofnikic/php-parser, but I did try to downgrade tov3.1.5and that solved the issue. Apparently there’s a bug inv4.*somewhere.Thanks again for your help @ikari7789 and @bobthecow!