PHP 8 in Visual Studio Code
Asked Answered
L

3

8

I use the latest Version of Visual Studio Code (1.52.1) with PHP Intelephense 1.5.4 on Ubuntu. Despite it is the latest Version it seems not to know the new PHP 8 Syntax. For example it shows an error when using the nullsafe operator:

$myobject?->myfunction();

Is there a way to teach VSC PHP 8 or do we have to just wait for an update?

Lacerta answered 17/12, 2020 at 17:8 Comment(0)
B
5

You should point Visual Studio Code to the location of PHP interpreter that you want to use.

You can do it by setting a line in the settings.json like this:

"php.validate.executablePath": "c:/usr/php8.1/php.exe",

It is a VSCode configuration option but seems to work with Intelephense too.

You can also do it on per project basis using a separate settings.json file residing in project's .vscode folder. You can find more on these options in the VSCode documentation.

Burst answered 9/6, 2022 at 10:10 Comment(1)
That worked. I added this to the settings-Section in my workspace save file (projectname.code-workspace).Lacerta
L
8

As you can see on https://github.com/bmewburn/vscode-intelephense/milestone/26: they are actively working on adding support for PHP8. Any further questions should be posted in their issue tracker


Best credible source, posted on Dec 09 on https://github.com/bmewburn/vscode-intelephense/issues/1525#issuecomment-742115154:

It's being actively worked on. Should be out soon.

Lorenalorene answered 17/12, 2020 at 17:11 Comment(1)
I've noticed strange thing - even though current marketplace version of intelephense is 1.8, my vscode still shows only 1.5.4, I had to uninstall it and install it again to get the latest extension version. However even if I set 8.1.2 for both User & Workspace "Intelephense › Environment: PHP Version" - named arguments are still red as errors.Gunwale
B
5

You should point Visual Studio Code to the location of PHP interpreter that you want to use.

You can do it by setting a line in the settings.json like this:

"php.validate.executablePath": "c:/usr/php8.1/php.exe",

It is a VSCode configuration option but seems to work with Intelephense too.

You can also do it on per project basis using a separate settings.json file residing in project's .vscode folder. You can find more on these options in the VSCode documentation.

Burst answered 9/6, 2022 at 10:10 Comment(1)
That worked. I added this to the settings-Section in my workspace save file (projectname.code-workspace).Lacerta
E
3

This answer solved my problem, even tho i don't use a mac.

I still had an old php version linked in my VSCode settings of my WSL integration (settings.json). Removing that line, fixed the errors.

Endopeptidase answered 8/6, 2022 at 15:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.