如何在VSCODE中使用PHP 8.1语法?

发布于 2025-02-10 06:09:52 字数 280 浏览 2 评论 0 原文

我在C驱动器上的PC上安装了PHP 8.1.4,

但我在驱动器D中有XAMPP,这些drive D中有所有PHP文件,并且我在XAMPP中有PHP 8.1.2

我在VSCODE上安装了php intephense,并且我禁用PHP语言功能

但是,当我写php 8或8.1语法时,我的vscode显示错误

I have PHP 8.1.4 installed on my PC on a C drive

but I have XAMPP in drive D which have all my PHP files and I have PHP 8.1.2 in XAMPP

I have PHP Intelephense installed on my VSCODE and I disable PHP Language Features

but still when I write PHP 8 or 8.1 syntax my vscode show error

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只是我以为 2025-02-17 06:09:52

您必须为PHP Intlephense扩展名为PHP版本指定。

2种方法:

  • 设置>偏好和键入“ Intlephense php版本”,然后Yo可以设置 8.1

。 alt =“”>

  • /qhhfp.png“ rel =” nofollow noreferrer“> ”与此:“ intelephense.environment.phpversion”:“ 8.1。*”

nb:检查您是否拥有 php intlephense 的最后版本也非常重要!

就是这样!

You have to specify your PHP version for the PHP intelephense extension.

2 ways to do that :

  • Settings > Preferences and typing "intelephense php version" and then yo can set 8.1.* instead 8.0.0 here :

  • edit your VSCODE settings.json with this : "intelephense.environment.phpVersion": "8.1.*".

NB : check if you have the lastest version of PHP Intelephense it also very important!

And that's it !

余生再见 2025-02-17 06:09:52

请注意,有两种设置 - 一个是用户的“主要”,对于 workspace 而言,工作空间具有更高的优先级。

  1. 通过在PHP内置扩展设置中设置PHP可执行文件来设置PHP版本
    • Extensions => php => php>验证:可执行路径
    • 您很可能必须通过“ in in steratings.json”
    • 进行设置

    • 修改看起来像“ php.validate.executablepath”:“/usr/bin/php8.2”
      • 当然要替换/usr/bin/php8.2 带有您自己的PHP EXE
      • 的路径

      • 如果您在Windows上挣扎,则可以从并链接 php.exe




  2. 设置PHP php intelephense扩展的版本:
    • Extensions => intlephense => intlephense>环境:PHP版本
      • 在这里您只能在版本本身中pu pu 8.2.0

还请注意,如果您完全违反了PHP文件,则可能不会在首先显示某些错误 - 就像一个错误的命名参数 - 这并不是一个完全完全损坏的。语法错误,但如果没有以前的语法错误(例如“ php parse error ...”等...

另请参阅: https://code.visualstudio.com/docs/languages/php 有关VSCODE本身如何完成linting的更多信息。

Note there are 2 type of settings - one is the "main" for the User and secondary for the Workspace, the workspace has higher priority.

  1. Set the PHP version by setting the PHP executable in the PHP built-in extension settings
    • Extensions => PHP => PHP > Validate: Executable Path
    • you will most likely have to set this through the "Edit in settings.json"
    • the modification will look like "php.validate.executablePath": "/usr/bin/php8.2"
      • of course replace /usr/bin/php8.2 with your own path to PHP exe
      • if you're struggling on Windows, you can download specific version of PHP into a custom directory from https://windows.php.net/download and link the php.exe
  2. Set the PHP version for the PHP Intelephense extension in the settings:
    • Extensions => intelephense => Intelephense > Environment: PHP Version
      • here you only pu in the version itself e.g. 8.2.0

Also note that if you have broken PHP file completely, some errors may not be shown at first - like a wrong named argument - which is not exactly a syntax error but is validated later if there are not previous syntax errors (like "PHP Parse error..." etc...

Also see: https://code.visualstudio.com/docs/languages/php for more information on how VSCode itself does the linting.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文