168

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

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
Fluffy
  • 27,504
  • 41
  • 151
  • 234
  • 2
    Why would it highlight `__construct()`? It's a perfectly valid function identifier in PHP4, it's just not being called as a constructor. – Mchl Nov 08 '10 at 09:33
  • 1
    @Mchl, is static function ok? – Fluffy Nov 08 '10 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. – Mchl Nov 08 '10 at 10:55
  • @Mchl `static $variable` perhaps, not `static function` – Fluffy Nov 08 '10 at 11:57
  • Maybe. I didn't work with PHP4 OOP – Mchl Nov 08 '10 at 12:33

9 Answers9

256

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.

biesior
  • 55,576
  • 10
  • 125
  • 182
Alejandro Moreno
  • 5,578
  • 2
  • 31
  • 29
125

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

Shay Altman
  • 2,720
  • 1
  • 16
  • 20
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.

Saeed
  • 3,294
  • 5
  • 35
  • 52
boolfalse
  • 1,892
  • 2
  • 13
  • 14
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
Burgi
  • 421
  • 8
  • 24
Salar
  • 5,305
  • 7
  • 50
  • 78
  • 2
    Could you see that is setting 'For current project'? How can I update it for Global (all projects)? – Vuong Mar 08 '18 at 07:43
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

Yassine CHABLI
  • 3,459
  • 2
  • 23
  • 43
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 :-)

Saeed
  • 3,294
  • 5
  • 35
  • 52
MrG
  • 372
  • 2
  • 13
2

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

IN

enter image description here

enter image description here

enter image description here

des1roer
  • 220
  • 1
  • 14
2

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

enter image description here

Apps-n-Add-Ons
  • 2,026
  • 1
  • 17
  • 28
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!

The Billionaire Guy
  • 3,382
  • 28
  • 31