使用composer global require "laravel/installer"
命令使用composer成功安装Laravel的安装工具后,首次尝试通过运行laravel new app-name
创建应用程序失败并显示以下输出,我们将不胜感激任何建议: )
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
答案 0 :(得分:17)
原来这个问题与系统上安装的guzzle版本有关。
在其他一些存储库/应用程序上看到关于guzzle 5.3的类似问题之后,通过运行composer global info guzzlehttp/guzzle
确认了我的全局安装版本,它是5.3。
然后通过运行composer global update
更新我的作曲家的全局安装解决了问题,在看到如下所示的更新报告后,运行相同的laravel new app-name
会成功生成应用程序。
更新guzzlehttp / guzzle(5.3.0 => 6.2.3):正在下载(100%)
答案 1 :(得分:3)
这与Guzzle的PHP 7.x不兼容性有关,这在Guzzle> = 5.3.1中已经fixed。
解决方案是通过将composer.json
文件中的行修改为:
"guzzlehttp/guzzle": "~5.3.1",
或:
"guzzlehttp/guzzle": "~5.3@stable",