13

My Code:

namespace App\Enum;

enum HomeStatus: string
{
    case RENT = 'rent';
    case MOVE_IN = 'move_in';
    case SOLD = 'sold';
    case COMING_SOON = 'coming_soon';
}

The code above is executing and working but the editor has the following error:

Unexpected 'Name'. Expected ';'.intelephense(1001)

I am using Intelephense v1.8.0 which I believe is the latest.

In the Change Log it says:

PHP 8.1 is now the default version.

I'm thinking that either that's not the case or PHP 8.1 does not yet have support for enums.

Is there a way to resolve this or is this something that is not yet supported?

EDIT As requested here's a screenshot of the error.

enter image description here

Kevin Pimentel
  • 2,056
  • 3
  • 22
  • 50
  • 3
    That error doesn't seem to be here, since there is no `Name` showing in your code. Can you show the code giving that error? – aynber Jan 07 '22 at 13:12
  • 1
    @aynber I agree the quotes are misleading, but that's seemingly the internal token name used by the language server. For example, if you type `class Foo {`, the error reads _Unexpected 'EndOfFile'_. – Álvaro González Jan 09 '22 at 13:07

2 Answers2

14

Open Visual Studio Code settings and ensure the intelephense.environment.phpVersion directive is set to "8.1.0" or greater. It can be set for the whole program or for specific projects.

intelephense.environment.phpVersion

{
    "intelephense.environment.phpVersion": "8.1.0"
}
Álvaro González
  • 142,137
  • 41
  • 261
  • 360
  • Thank you, this solved my problem. I went into `settings.json` and I added `"intelephense.environment.phpVersion": "8.1.0"` – Kevin Pimentel Jan 07 '22 at 15:47
3

For me, Alvaro's solution was only half of the fix. I also had to update this setting to point to my PHP executable.

{
"php.validate.executablePath": "C://laragon//bin//php//php-8.1.3-Win32-vs16-x64//php.exe"
}
Bennett
  • 585
  • 1
  • 12
  • 24
  • This doesn't work when using WSL – mbomb007 May 23 '22 at 13:57
  • This setting doesn't belong to PHP Intelephense, it's from builtin PHP Language Features which, according to [Quick Start](https://marketplace.visualstudio.com/items?itemName=bmewburn.vscode-intelephense-client), needs to be disabled. – Álvaro González Jun 05 '22 at 12:59