Wamp环境下执行Magento bin/magento命令遇语法解析错误求助
Hey there, let's break down what's going on here and fix that frustrating error. The core problem is that even though you intended to use PHP 7.0.23 for Magento, your command line is still running the default PHP 5.6.31 from Wampserver. Magento 2.x uses PHP 7+ syntax that PHP 5.6 can't parse, which is why you're seeing that "unexpected 'try'" error when it hits line 13 of bin/magento.
Here's how to resolve this step by step:
Confirm your current CLI PHP version
Open a fresh command prompt and run:php -vIf this still shows 5.6.31, your PATH update didn't take effect in the active terminal session, or Wampserver's PHP version switch didn't apply to the command line environment.
Properly switch PHP versions in Wampserver
Right-click the Wampserver tray icon, navigate toPHP > Version, and select 7.0.23. Wait for Wampserver to restart all services (the tray icon will turn green again once it's done).Refresh your terminal's PATH settings
Close all open command prompt windows, then open a new one. Runphp -vagain to confirm you're now running PHP 7.0.23. This ensures the terminal picks up the updated PATH configuration.Bypass PATH issues with an explicit PHP call
If the above steps still don't fix the PATH problem, skip it entirely by running the Magento command with the full path to your PHP 7.0 executable:C:/wamp64/bin/php/php7.0.23/php.exe C:/my-project-root/bin/magento setup:upgradeAdjust the PHP path to match where Wampserver stores your PHP 7.0.23 installation (it might be slightly different depending on your Wampserver version).
Quick compatibility check
Just to be safe: most Magento 2.1, 2.2, and early 2.3 releases are fully compatible with PHP 7.0.23, so this shouldn't be a blocker once you're using the correct PHP version.
内容的提问来源于stack exchange,提问作者Thibault

