How can I set the PHP version in PHPStorm?

PhpIdePhpstorm

Php Problem Overview


Is it possible to set the PHP version value, say 4.0+ and have PHPStorm highlight functions that wouldn't work with the oldest version? For example, for PHP4 this should highlight static function etc. I have a PHP installation on my PC but I don't want to install an older PHP version for every small script I have to produce.

Thanks

Php Solutions


Solution 1 - Php

So, you mean to highlight all pieces of code that will not work with the PHP version you are writing it in, right? That can be done here:

Preferences -> Languages & Frameworks > PHP

and the same on Mac:

PhpStorm -> Preferences (⌘,) -> Languages & Frameworks > PHP

Or with newer versions of PhpStorm in Windows:

File -> Settings -> Languages & Frameworks > PHP

Sample dialogbox for mentioned prefrences

then select your PHP version, for example, 7.0

This is very useful when your local system runs PHP 7.0, for example, but production is running PHP 5.5.

That way PhpStorm will warn you which parts will not work in production, show proper hints during writing code according to the selected version, etc.

Solution 2 - Php

In case your field is disabled.

Probably your settings "Synchronize IDE settings with composer.json" is enabled

You may change your PHP version in composer.json file

"require": {
    "php": ">=7.1.0",
}

OR disable your settings in this path

File -> Settings -> Languages & Frameworks > PHP > Composer

If you change your composer.json file - As [Félix Gagnon-Grenier][1] commented, Keep in mind it has effects on the way packages will be required later [1]: https://stackoverflow.com/users/576767/f%C3%A9lix-gagnon-grenier

Solution 3 - Php

You can use Alejandro Moreno's answer, but sometimes you might not be able to change PHP level from closed dropdown.

You can disable "Synchronize IDE settings with composer.json" checkbox from:

File -> Setting -> Languages & Frameworks -> PHP -> Composer

And after applying again open

File -> Settings -> Languages & Frameworks -> PHP

Here You can change PHP level from opened dropdown.

Solution 4 - Php

Open the Settings dialog box by choosing File | Settings, then click PHP under Languages & Frameworks. The PHP page opens.

Screenshot of the PHP settings

Now you can do 2 things:

  1. On the PHP page that opens you can set the "PHP Language Level".
  2. You can install the PHP version that you wish locally by, for example, installing packages like wamp or xamp and then set the interpreter of your PHP on the PHP page that you opened. More info here

Solution 5 - Php

You can set this per project, as outlined by @Alejandro Moreno.

There is also a global setting, that allows you to set the PHP Language Level for all NEW projects.

File --> Preferences for New Projects --> Languages & Frameworks --> PHP

Here you can set the desired level for all future projects :-)

Solution 6 - Php

My composer PHP version is synchronized to the phpstorm , so to explicitly choose the php language level from the setting, check that the option in the picture bellow is disabled.

enter image description here

Solution 7 - Php

in picture ..........................

IN

enter image description here

enter image description here

enter image description here

Solution 8 - Php

On Mac, it is under PHPStorm, Preferences, Languages & Frameworks, PHP

enter image description here

Solution 9 - Php

just like @mohammed my composer PHP version was synchronized to my phpstorm. so all i did was to update my composer.json php version number and it affected the whole project.

dont forget to composer update and php artisan config:clear

happy coding!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFluffyView Question on Stackoverflow
Solution 1 - PhpAlejandro MorenoView Answer on Stackoverflow
Solution 2 - PhpShay AltmanView Answer on Stackoverflow
Solution 3 - PhpboolfalseView Answer on Stackoverflow
Solution 4 - PhpSalarView Answer on Stackoverflow
Solution 5 - PhpMrGView Answer on Stackoverflow
Solution 6 - PhpYassine CHABLIView Answer on Stackoverflow
Solution 7 - Phpdes1roerView Answer on Stackoverflow
Solution 8 - PhpApps-n-Add-OnsView Answer on Stackoverflow
Solution 9 - PhpThe Billionaire GuyView Answer on Stackoverflow