172

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

5
  • 2
    Why would it highlight __construct()? It's a perfectly valid function identifier in PHP4, it's just not being called as a constructor. Commented Nov 8, 2010 at 9:33
  • 1
    @Mchl, is static function ok? Commented Nov 8, 2010 at 10:35
  • static was avaialbe in PHP4 as well IIRC. Try abstract or use of visibility modifiers public,protected,private. Anyway, writing OO code that's supposed to work under PHP4 as well as PHP5 is a nonsensical task IMO. The object model differs too much between the two. Commented Nov 8, 2010 at 10:55
  • @Mchl static $variable perhaps, not static function Commented Nov 8, 2010 at 11:57
  • Maybe. I didn't work with PHP4 OOP Commented Nov 8, 2010 at 12:33

9 Answers 9

265

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.

Sign up to request clarification or add additional context in comments.

6 Comments

What version do you use? I don't have that option in mine.
Sorry, I should have specified that: 7.1.3
Can we do this per project or is this only "global"?
For the current version of PhpStorm: PhpStorm 2016.3.2. It should be File -> Settings -> Languages & Frameworks -> PHP.
and do not forget, if you got old phpstrorm(for example 2018.x) you will not see a 7.4 in PHP language level !
|
126

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 commented, Keep in mind it has effects on the way packages will be required later

4 Comments

This answer is not really accurate. Doing that will change the language level if (and only if) the "synchronise with composer" option is checked. Moreover, it has effects on the way packages will be required later.
It helped me understanding why the PHP language level selection was disabled.
In my case phpstorm was looking to another composer.json so I changed it and problem was solved. Thanks!
Why is PhpStorm not using config.platform.php for this?
24

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.

Comments

22

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

1 Comment

Could you see that is setting 'For current project'? How can I update it for Global (all projects)?
5

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

Comments

4

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 :-)

Comments

2

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

IN

enter image description here

enter image description here

enter image description here

Comments

2

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

enter image description here

Comments

0

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!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.