The spread operator allows you to pass a list of parameters, and the function take these parameters as an array. In PHP you can use the variable argument list operator "...
".
http://docs.php.net/manual/en/functions.arguments.php#functions.variable-arg-list
Example:
<?php
function sum(...$numbers) {
$acc = 0;
foreach ($numbers as $n) {
$acc += $n;
}
return $acc;
}
echo sum(1, 2, 3, 4);
?>
Using your example:
class Foo {
var $id;
var $name;
var $value;
public function __construct(...$params) {
$this->id=$params[0];
$this->name=$params[1];
$this->value=$params[2];
}
}
Then call :
$var=new Foo(1, 'some name', 'some value');
In your case, you are trying to pass an array of parameters to a function. In this case you can omit the "..." operator and pass the elements:
class Foo {
var $id;
var $name;
var $value;
public function __construct($params) {
$this->id=$params[0];
$this->name=$params[1];
$this->value=$params[2];
}
}
Then call :
$arr = array(1, 'some name', 'some value');
$fooObj = new Foo($arr);