closure icon indicating copy to clipboard operation
closure copied to clipboard

Error when using PHP 8 named parameters

Open Chi-teck opened this issue 3 years ago • 2 comments

Code example

function hello(string $name): void {
    echo "Hello $name!";
}

$example = function () {
    hello(name: 'Foo');
};

$wrapper = new SerializableClosure($example);
$result = unserialize(serialize($wrapper));

Result

PHP Parse error:  syntax error, unexpected token ":", expecting ")" in closure://function (): void {
    \hello(\name: 'Foo');
} on line 3

Chi-teck avatar Jan 18 '21 11:01 Chi-teck

Opis 3.6.1 does not support all new PHP 8 syntax. It supports all PHP 7.4 syntax on PHP 8.0, but not all new 8.0 syntax on 8.0 (it does support union types, but not named parameters).

GrahamCampbell avatar Jan 18 '21 12:01 GrahamCampbell

This repo is open to PRs if you'd like to implement it.

GrahamCampbell avatar Jan 18 '21 12:01 GrahamCampbell