Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mike12345's avatar

laravel 5.0, error with tinker on php7 ('String' is a special class name error)

Hi, I'm having trouble resolving an issue I'm having with 'php artisan tinker'. When I run tinker, I get the following:

$ php artisan tinker
PHP Fatal error:  Cannot use PhpParser\Node\Scalar\String as String because 'String' is a special class name in /home/vagrant/Code/jobscan2/vendor/psy/psysh/src/Psy/CodeCleaner/MagicConstantsPass.php on line 19

  [Symfony\Component\Debug\Exception\FatalErrorException]
  Cannot use PhpParser\Node\Scalar\String as String because 'String' is a special class name

I'm using Laravel 5.0 and my site seems to be running fine with php7, but tinker doesn't work. Has anyone encountered this / know how to resolve it? I've run 'composer update', but it hasn't helped. From what I can tell in composer.lock: laravel/framework 5.0.34 requires psy/psysh 0.4.*

psy/psych 0.4.4 then requires nikic/php-parser ~1.0

But this doesn't seem to be compatible with php7 (according to https://github.com/nikic/PHP-Parser, I should be using 2.0+). Are people successfully using php artisan tinker from laravel 5.0 on php7? Any ideas what I need to do to fix tinker? Thanks in advance.

0 likes
7 replies
gamingumar's avatar

yea, i am having the same problem, tinker throws error with php 7 and i really want to upgrade to php 7 with laravel

spekkionu's avatar

Laravel 5.2 runs fine on php7.
The best solution might be to upgrade your app.

zubaer_ahammed's avatar

In php 7 'String' is a special Class name.

The best solution is to upgrade your Laravel version.

But if you need to use older version, you can replace String with String_

At /vendor/psy/psysh/src/Psy/CodeCleaner/MagicConstantsPass.php on line 19, you will find two 'String', just replace them with 'String_'.

manni's avatar

and at /vendor/psy/psysh/src/Psy/Readline/Libedit.php on line 14

use Psy\Util\String as String_;
collabmed's avatar

PHP Fatal error: Cannot use Psy\Util\String as String because 'String' is a special class name in /home/john/Documents/test/vendor/psy/psysh/src/Psy/Readline/Libedit.php on line 14

screwtape_mk's avatar

did @mike12345 end up voting the correct answer here? I am having the same issue and dont want to update my version of laravel just yet.

Please or to participate in this conversation.