Unexpected token '(' in named argument inspection despite composer.json PHP 8.1 requirement
0 reputation · 02 May 2021, 04:24 UTC
0 reputation · 02 May 2021, 04:24 UTC
Goal: Configure PHPStorm to automatically use the PHP version declared in composer.json for its language‑level inspections so that valid modern syntax is not flagged as errors.
Constraints: The IDE does not read the require → php field from composer.json; the language level must be set manually via Settings | Languages & Frameworks | PHP. The quick‑fix “Set PHP language level to X” appears only after a file containing the offending construct is opened, and the chosen level is stored per‑project in the .idea workspace, which is not typically version‑controlled, requiring each developer to apply it individually.
composer.json PHP requirement and set the language level automatically on project load?.idea/misc.xml or a dedicated XML) so that all team members receive the same inspection baseline?35275 reputation · 02 May 2021, 07:30 UTC
1. No – PHPStorm does not automatically read the require‑>php field from composer.json and adjust the language level when a project is opened.
2. No – The quick‑fix “Set PHP language level to X” is a file‑contextual action that appears only after a file containing out‑of‑range syntax is opened; it cannot be triggered programmatically or from the command line.
3. Yes, with caveats – The language level is stored in .idea/misc.xml. You can edit this file to add <option name="languageLevel" value="8.1"/> and commit the file, but JetBrains recommends keeping .idea out of VCS because different developers may use different PHP interpreters, which can lead to merge conflicts or unwanted overrides.
php requirement is a runtime constraint, not an IDE configuration. The IDE has no API to query Composer automatically on project load..idea/misc.xml. It is intentionally tied to file opening to avoid surprises when a file contains syntax that is only valid in a newer PHP version.Settings | Languages & Frameworks | PHP./usr/local/bin/php8.1).8.1 if the interpreter’s version matches..idea/misc.xml and look for <option name="languageLevel" value="8.1"/>. If it’s missing, add it manually..idea/misc.xml to VCS only if all developers use the same PHP interpreter. Keep the file under version control only if you’re comfortable with potential merge conflicts..phpstorm.project file that sets the interpreter path or use a script to set the interpreter on project load (e.g., via a wrapper that calls phpstorm.sh --php-8.1).If the PHP interpreter on a developer’s machine is older than the version required by composer.json, PHPStorm will still flag newer syntax as errors regardless of the composer.json setting. In that scenario, please confirm the interpreter path configured in Settings | Languages & Frameworks | PHP for each developer.
.idea/misc.xml is possible but discouraged unless all team members share the same interpreter setup.Use comments to ask for clarification. Post a solution as an answer.
35,275 reputation · 02 May 2021, 10:03 UTC
PHPStorm derives the language level solely from the PHP interpreter configured for the project. It does not read composer.json automatically, so the require‑>php field is ignored during inspection setup.
<option name="languageLevel" value="8.1"/>
Commit this change to VCS. JetBrains recommends keeping .idea out of source control, but for a shared language level this is the most straightforward path..phpstorm.yml in the project root with
php:
language_level: "8.1"
This file is VCS‑friendly and is read on project load..idea/misc.xml or .phpstorm.yml, re‑import the project or restart PHPStorm to apply the new language level.