Can the PHP-version in PhpStorm be set via a configuration file in the project?

Viewed 22

I'm jumping between projects, and it's often that the PHP-version of the project doesn't match, the PHP-version of that project:

PHP version

This happens mostly, when I clone a repository and open it in PhpStorm. Sometimes the PHP language level is set to 7.2, other time it is set to 8.0, while I always have 7.4 installed locally.

If I just start a new blank project, then it is set correctly:

PHP version 2

Can that PHP-language level be set somewhere from the files (in the same way as .editorstyle)?

1 Answers

PhpStorm can use composer.json to get this info, the following key:

"require": {
    "php": "^7.4"
}

Make sure you have Settings/Preferences | PHP | Composer | Synchronize IDE Settings with composer.json option enabled (which is enabled by default anyway). This way the IDE will read that setting every time you open the project.

https://www.jetbrains.com/help/phpstorm/composer-page.html

enter image description here

The IDE should take the lowest version if you have more than one (e.g. from ^7.4|^8.0 it should take 7.4) -- if your code can run on both PHP 7.4 and 8.0 then it should use the lower version (because if you start using PHP 8.0 features then it cannot run on PHP 7.4 any longer).


Other than that (for the projects that do not use composer.json or the aforementioned option is disabled): you can set the defaults for new projects at File | New Project Setup | Settings for New Projects....

Related