Answer the question first
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.
Why the IDE behaves this way
- PHPStorm determines the language level solely from the configured PHP interpreter (Settings → Languages & Frameworks → PHP). The interpreter’s version is the source of truth for the language level.
- Composer is a dependency manager; its
php requirement is a runtime constraint, not an IDE configuration. The IDE has no API to query Composer automatically on project load.
- The quick‑fix is a user‑initiated action that writes the chosen level to
.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.
Practical steps for your case
- Set the interpreter to PHP 8.1:
- Open
Settings | Languages & Frameworks | PHP.
- Choose or add the PHP 8.1 executable (e.g.,
/usr/local/bin/php8.1).
- The Language level dropdown will automatically update to
8.1 if the interpreter’s version matches.
- Verify the setting:
- Open
.idea/misc.xml and look for <option name="languageLevel" value="8.1"/>. If it’s missing, add it manually.
- Restart PHPStorm and open a file that uses named arguments. The inspection should no longer flag the syntax.
- Persisting across team members:
- Commit
.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.
- Alternatively, create a shared
.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).
When to ask for more information
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.
Key take‑aways
- Use the PHP interpreter as the single source of truth for the language level.
- The quick‑fix is file‑contextual and cannot be triggered without opening a file.
- Persisting
.idea/misc.xml is possible but discouraged unless all team members share the same interpreter setup.