Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel CLI fails to create new app due to Cannot use lexical variable $eventName as a parameter name

After successful installation of Laravel's install tool using composer using composer global require "laravel/installer" command, the first attempt to create an application by running laravel new app-name fails with the following output, any advice will be appreciated :)

Crafting application...
PHP Fatal error:  Cannot use lexical variable $eventName as a parameter name in /Users/ABN/.composer/vendor/guzzlehttp/guzzle/src/Event/Emitter.php on line 48
PHP Stack trace:
PHP   1. {main}() /Users/ABN/.composer/vendor/laravel/installer/laravel:0
PHP   2. Symfony\Component\Console\Application->run() /Users/ABN/.composer/vendor/laravel/installer/laravel:13
PHP   3. Symfony\Component\Console\Application->doRun() /Users/ABN/.composer/vendor/symfony/console/Application.php:126
PHP   4. Symfony\Component\Console\Application->doRunCommand() /Users/ABN/.composer/vendor/symfony/console/Application.php:195
PHP   5. Laravel\Installer\Console\NewCommand->run() /Users/ABN/.composer/vendor/symfony/console/Application.php:878
PHP   6. Laravel\Installer\Console\NewCommand->execute() /Users/ABN/.composer/vendor/symfony/console/Command/Command.php:259
PHP   7. Laravel\Installer\Console\NewCommand->download() /Users/ABN/.composer/vendor/laravel/installer/src/NewCommand.php:52
PHP   8. GuzzleHttp\Client->get() /Users/ABN/.composer/vendor/laravel/installer/src/NewCommand.php:125
PHP   9. GuzzleHttp\Client->createRequest() /Users/ABN/.composer/vendor/guzzlehttp/guzzle/src/Client.php:125
PHP  10. GuzzleHttp\Client->getEmitter() /Users/ABN/.composer/vendor/guzzlehttp/guzzle/src/Client.php:115
PHP  11. spl_autoload_call() /Users/ABN/.composer/vendor/guzzlehttp/guzzle/src/Event/HasEmitterTrait.php:15
PHP  12. Composer\Autoload\ClassLoader->loadClass() /Users/ABN/.composer/vendor/guzzlehttp/guzzle/src/Event/HasEmitterTrait.php:15
PHP  13. Composer\Autoload\includeFile() /Users/ABN/.composer/vendor/composer/ClassLoader.php:322
like image 262
Ali Avatar asked May 21 '17 18:05

Ali


2 Answers

Turned out the issue is related to the guzzle version installed on the system.

After seeing similar issue reported around guzzle 5.3 on some other repositories/apps, confirmed my globally installed version by running composer global info guzzlehttp/guzzle and it was 5.3. Then updating my composer's global installation by running composer global updatesolved the problem, after seeing the update report as shown bellow, running the same laravel new app-name generates the application successfully.

Updating guzzlehttp/guzzle (5.3.0 => 6.2.3): Downloading (100%)

like image 91
Ali Avatar answered Oct 05 '22 22:10

Ali


This is related to Guzzle's PHP 7.x incompatibility and this has been fixed in Guzzle >=5.3.1.

The solution is to upgrade your Guzzle by modifying line in your composer.json file to:

"guzzlehttp/guzzle": "~5.3.1",

or:

"guzzlehttp/guzzle": "~5.3@stable",
like image 35
kenorb Avatar answered Oct 05 '22 22:10

kenorb