uniter icon indicating copy to clipboard operation
uniter copied to clipboard

... operator not supported for variadic functions or argument unpacking

Open mortenson opened this issue 2 years ago • 1 comments

Hi there! First just wanted to say thanks for making this super ambitious project, I had no idea that PHP to JS transpilation was possible.

I noticed that the ... is not supported for variadic functions or argument unpacking, which were new features in PHP 5.6: https://www.php.net/manual/en/migration56.new-features.php

You can replicate this by running a PHP file like this with uniter :

function f($req, $opt = null, ...$params) {
  // $params is an array containing the remaining arguments.
  printf('$req: %d; $opt: %d; number of params: %d'."\n",
         $req, $opt, count($params));
}

f('req', 'opt', 'foo', 'bar', 'zed');

function add($a, $b, $c) {
  return $a + $b + $c;
}

$operators = [2, 3];
echo add(1, ...$operators);

You should get the error:

> uniter index.php

PHP Parse error:  syntax error, unexpected '.' in x on line y

Parse error: syntax error, unexpected '.' in x on line y

mortenson avatar Apr 02 '22 16:04 mortenson

Thanks for the great feedback @mortenson ! You're quite right that neither of those are supported yet but should be - I'll leave this issue open until they have been.

Cheers!

asmblah avatar Apr 04 '22 21:04 asmblah