PHP8 VS Code: Compiler throws error when using union types

Viewed 398

I am using Visual Studio Code to code PHP8. I wanted to try the strict types declare(strict_types=1).

When using single types, everything is fine:

function doSomething(int $value): ?float
{
    if ($value === null) return null;
    return round($value, 3);
}

When using union types, the compiler throws errors:

function doSomething(int|string $value): ?float
{
    if ($value === null) return null;
    return round($value, 3);
}

Errors:

'VariableName' expected
')' expected
'{' expected
Unexpected '|'
';'
...

I disabled the PHP language features and I am using the PHP Intelephense v1.8.0 extension.

0 Answers
Related