如何在 PHPStorm 中设置 PHP 版本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4122585/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I set the PHP version in PHPStorm?
提问by Fluffy
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.
是否可以设置 PHP 版本值,例如 4.0+ 并具有不适用于最旧版本的 PHPStorm 突出显示功能?例如,对于 PHP4,这应该突出显示static function
等。我在我的 PC 上安装了 PHP,但我不想为我必须生成的每个小脚本安装旧的 PHP 版本。
Thanks
谢谢
回答by Alejandro Moreno
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:
所以,您的意思是突出显示所有不适用于您正在编写的 PHP 版本的代码,对吗?这可以在这里完成:
Preferences -> Languages & Frameworks > PHP
Or with newer versions of PhpStorm:
或者使用较新版本的 PhpStorm:
File -> Settings -> Languages & Frameworks > PHP
then select your PHP version, for example, 7.0
然后选择您的 PHP 版本,例如 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.
例如,当您的本地系统运行 PHP 7.0 但生产环境运行 PHP 5.5 时,这非常有用。这样 phpstorm 会警告你哪些部分不能在生产中工作。
回答by Shay Altman
In case your field is disabled.
如果您的字段被禁用。
Probably your settings "Synchronize IDE settings with composer.json" is enabled
可能您的设置“与 composer.json 同步 IDE 设置”已启用
You may change your PHP version in composer.json
file
您可以在composer.json
文件中更改您的 PHP 版本
"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-Greniercommented, Keep in mind it has effects on the way packages will be required later
*如果您更改了 composer.json 文件 - 正如Félix Gagnon-Grenier评论的那样,请记住它会影响以后需要包的方式
回答by Salar
Open the Settings dialog box by choosing File | Settings, then click PHPunder Languages & Frameworks. The PHP page opens.
通过选择文件 |打开设置对话框。设置,然后单击语言和框架下的PHP。PHP 页面打开。
Now you can do 2 things:
现在你可以做两件事:
- On the PHP page that opens you can set the "PHP Language Level".
- 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
- 在打开的 PHP 页面上,您可以设置“PHP 语言级别”。
- 您可以在本地安装您想要的 PHP 版本,例如,安装 wamp 或 xamp 等软件包,然后在您打开的 PHP 页面上设置 PHP 的解释器。更多信息在这里
回答by boolfalse
You can use Alejandro Moreno's answer, but sometimes you might not be able to change PHP level from closed dropdown.
您可以使用Alejandro Moreno 的回答,但有时您可能无法从关闭的下拉列表中更改 PHP 级别。
You can disable "Synchronize IDE settings with composer.json" checkbox from:
您可以从以下位置禁用“与 composer.json 同步 IDE 设置”复选框:
File -> Settings -> Languages & Frameworks -> PHP -> Composer
文件 -> 设置 -> 语言和框架 -> PHP -> Composer
And after applying again open
再次申请后打开
File -> Settings -> Languages & Frameworks -> PHP
文件 -> 设置 -> 语言和框架 -> PHP
Here You can change PHP level from opened dropdown.
在这里您可以从打开的下拉菜单中更改 PHP 级别。
回答by MrG
You can set this per project, as outlined by @Alejandro Moreno.
您可以按照@Alejandro Moreno 的概述为每个项目设置此项。
There is also a global setting, that allows you to set the PHP Language Level for all NEWprojects.
还有一个全局设置,允许您为所有新项目设置 PHP 语言级别。
File --> Preferences for New Projects --> Languages & Frameworks --> PHP
文件 --> 新项目的首选项 --> 语言和框架 --> PHP
Here you can set the desired level for all future projects :-)
您可以在此处为所有未来项目设置所需的级别:-)
回答by CFP Support
回答by des1roer
回答by Mohammed Yassine CHABLI
回答by The Dead Guy
just like @mohammedmy 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.
就像@mohammed一样,我的 Composer PHP 版本与我的 phpstorm 同步。所以我所做的只是更新我的 composer.json php 版本号,它影响了整个项目。
dont forget tocomposer update
andphp artisan config:clear
不要忘记composer update
和php artisan config:clear
happy coding!
快乐编码!