2

In code written in PHP8.1 I use named arguments in a method call:

// function definition
public function myFunction(string $name, string $description = "")
// method call with errors
->myFunction(name: self::SOME_CONSTANT)

however extension PHP Intelephense shows 2 errors there:
Undefined constant 'App\Some\Namespace\name'.intelephense(1011)
and Unexpected ':'.intelephense(1001)

I tried already following (with no success):

  • System-wide install PHP8.1 and set it as the default version (cli version PHP 8.1.2)
  • Setting these for both User && Workspace
    • "intelephense.environment.phpVersion": "8.1.2",
    • "php.validate.executablePath": "/usr/bin/php8.1",
  • Restart (closing vscode completely and reopening the workspace folder again)

EDIT / ANSWER - Update your VSCODE to LATEST!

If you're not sure where to find out - check out Help > About and then vscode updates website. The issue in the end really was an issue of an outdated Visual Studio Code which caused extensions not to be properly updated. How did this happen? I was accidentally using vscode from apt install code which didn't update itself and it CAN be installed alongside the snap version - for ubuntu, the solution was to remove the the apt code and just keep the snap version or install it with sudo snap install --classic code - thanks goes to https://askubuntu.com/a/1217734/277898 for me to realize x)

jave.web
  • 13,880
  • 12
  • 91
  • 125

0 Answers0