Parse error: syntax error, unexpected '|', expecting variable (T_VARIABLE) Symfony PHP VERSION WAMP Windows
This specific stack trace points directly to a mismatch between the PHP interpreter executing Composer and the version required by the installed packages. The error Parse error: syntax error, unexpected '|', expecting variable on vendor\psr\log\src\LoggerInterface.php indicates that Composer is attempting to load code written for PHP 8.0+ or later (specifically using union types introduced in PHP 8) against a runtime environment that does not support it.
Although your composer.json explicitly configures the platform requirements, and your phpinfo() output confirms you are running PHP 7.4.9, the error persists. This discrepancy usually stems from WAMP's architecture on Windows. WAMP often installs multiple PHP versions in parallel (e.g., 7.2, 7.3, 7.4, 8.x) and defaults to a specific version for the web server or CLI that differs from what you expect.
The core issue is likely that the php executable invoked by Composer during the installation phase is not the PHP 7.4.9 binary you inspected via php -v in your terminal, or Composer itself is running under a different PHP version than the one defined in your project configuration.
Inspecting the Composer Environment
Before altering configurations, you must verify which PHP interpreter is actually powering Composer. Open your command prompt or PowerShell and run:
composer --version
Look closely at the output. It typically displays something like Composer version X.Y.Z (using PHP Z.Z.Z.Z). If this PHP version is lower than 7.1, you will encounter syntax errors immediately. However, even if Composer reports a higher version, the specific error regarding the pipe operator | suggests the vendor directory contains files incompatible with the current runtime.
Check your system PATH and WAMP settings to ensure consistency. On Windows, it is common for the php.exe used by Apache (via WAMP) to differ from the one in your System PATH. If you installed PHP 8 alongside PHP 7.4, Composer might be picking up the newer binary by default while expecting the older syntax constraints defined in your composer.json.
The Platform Configuration Limitation
Your composer.json includes a config.platform.php setting:
"config": {
"platform": {
"php": "7.4.9"
}
}
This flag tells Composer to simulate a PHP 7.4 environment when resolving dependencies, ensuring packages are installed compatible with that version. However, this setting only works if the local filesystem actually contains source code for PHP 7.4. It does not magically translate syntax errors from your actual runtime if the vendor files have already been corrupted or if Composer is using a cached lock file generated on a different machine or version.
Since you attempted to delete vendor and composer.lock, ensure that the installation process completes without interruption. Sometimes, an interrupted install leaves partial files in vendor/psr/log. Run the following command to force a fresh install while respecting your platform constraints:
composer update --no-scripts --with-all-dependencies
The --no-scripts flag prevents post-install commands from running immediately, which can sometimes mask errors or trigger conflicts during the initial setup phase. Once the dependencies are correctly resolved, you can re-enable scripts.
WAMP-Specific Troubleshooting
If the issue persists after a clean install, the problem is almost certainly related to how WAMP handles PHP versions. You need to force Composer and your project to use the exact same PHP binary.
- Verify WAMP's Active PHP Version: Open WAMP tray -> PHP Settings -> check which version is marked as "Active". Ensure it matches 7.4.9.
- Update Apache Configuration: If you are running the application via Apache, ensure that
AddHandlerdirectives in your.htaccessorhttpd.confpoint to the correctC:\wamp64\bin\php\php7.4.9\php.exe. - Force Composer PHP Path: Explicitly tell Composer which PHP binary to use:
composer config --global bin-dir vendor/bin
More importantly, ensure you are running Composer from the directory containing your vendor folder using the specific WAMP PHP path if necessary. In many cases, simply switching the active PHP version in WAMP to 7.4 and restarting the services resolves the parser mismatch without needing manual path adjustments.
Conclusion on Version Mismatches
The error is not a bug in Symfony or PSR; it is a runtime environment inconsistency. The union type syntax | was introduced in PHP 8.0. If you see this error on line 30 of LoggerInterface.php, it implies the file being parsed contains PHP 8 syntax, but your interpreter is reporting an incompatibility.
Double-check that no other PHP versions are shadowing your path. If you must use Symfony 4.4 with PHP 7.4, ensure that Composer is not pulling in a development branch of psr/log that requires PHP 8. Your composer.json already restricts PHP to >=7.1.3, but the specific version of psr/log being pulled might be incompatible if your local environment is confused about which version of PHP is active. Stick strictly to PHP 7.4 for both CLI and Apache within WAMP to resolve this parser conflict.