4

When I use the composer to install Laravel 5 I get this error:

Cannot use 'PhpParser\Node\Scalar\String' as class name as it is reserved in /Applications/XAMPP/xamppfiles/htdocs/learnlaravel5/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinter/Standard.php on line 86

Image of the error here

What is wrong?

SamV
  • 7,548
  • 4
  • 39
  • 50
葛文瑞
  • 43
  • 1
  • 3

3 Answers3

12

I assume you are using PHP7 as you wouldn't get this error otherwise (?).

In PHP7 String is now a reserved keyword along with some others. The PHP-Parser library used this keyword but was since fixed in April 2015. Try upgrading the PHP-Parser library, this should help.

SamV
  • 7,548
  • 4
  • 39
  • 50
6

Following @SamV's answer, this problem may cause the post-create-project-cmd not to run. As a result you won't have .env file. To compensate for this you can run them manually from within your project folder in the terminal as follows.

cp .env.example .env
php artisan key:generate

You can see what scripts are actually being run by checking the scripts section of the composer.json file.

Mahdi
  • 192
  • 11
0

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_.