How can I set the PHP version in PHPStorm?

。_饼干妹妹 提交于 2019-12-03 06:26:00

问题


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


回答1:


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

Or with newer versions of PhpStorm:

File -> Settings -> Languages & Frameworks > PHP

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.




回答2:


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




回答3:


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

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



回答4:


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 -> Settings -> Languages & Frameworks -> PHP -> Composer

And after applying again open

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

Here You can change PHP level from opened dropdown.




回答5:


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




回答6:


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




回答7:


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

IN



来源:https://stackoverflow.com/questions/4122585/how-can-i-set-the-php-version-in-phpstorm

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!