You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Symfony 4.0搭配MAMP PHP7.2时bin/console文件PHP语法错误求助

Why That Symfony Console Line Throws a Syntax Error

Ah, I’ve seen this exact headache with MAMP users so many times—let’s break this down clearly.

The syntax error is triggered by the null coalescing operator (??) in that line: $_SERVER['APP_ENV'] ?? 'dev'. This operator was introduced in PHP 7.0, so any PHP version older than that will throw a syntax error when it hits this code.

Here’s the catch: even though you’ve set MAMP to use PHP 7.2 for your web environment, your terminal (command-line interface, or CLI) is almost certainly using an older PHP version. Most macOS systems come pre-installed with PHP 5.x, and if you haven’t configured your environment variables to point to MAMP’s PHP, running php bin/console will default to that outdated system PHP instead of your MAMP 7.2 setup.

How to Fix This Step-by-Step

  1. Check your CLI PHP version first
    Run this command in your terminal to confirm:

    php -v
    

    If the output shows a version lower than 7.0, that’s definitely the problem.

  2. Point your terminal to MAMP’s PHP 7.2
    Open your shell configuration file (this is either ~/.bash_profile, ~/.bashrc, or ~/.zshrc depending on which terminal shell you use) and add this line at the end:

    export PATH=/Applications/MAMP/bin/php/php7.2.XX/bin:$PATH
    

    Replace php7.2.XX with the exact folder name of your PHP 7.2 installation in MAMP (you can find this by navigating to /Applications/MAMP/bin/php/—it’ll look like php7.2.34 or similar).

  3. Reload your shell settings
    Run this command to apply the changes right away:

    source ~/.bash_profile # Use ~/.zshrc if you're using Zsh
    

    Now re-run php -v—it should show PHP 7.2 as the active version.

  4. Test the Symfony console again
    Run php bin/console and the syntax error should be gone for good.

Just to confirm: Symfony 4.0 requires PHP 7.1.3 or higher, so your MAMP 7.2 setup is fully compatible—you just needed to make sure your terminal uses the same PHP version as your web server.

内容的提问来源于stack exchange,提问作者Baba Zannah

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:32:18