What is the name of the operator ... used in PHP 5.6?

5

From PHP 5.6 we now have the possibility to invoke or declare a function, stating that the arguments are infinite, using the ... operator.

Example:

function add(... $arguments)
{
    return array_sum($arguments);
}

add(1, 2, 3); // imprime: 6

Example 2:

print_r(...[$object, false]);
// é equivalente a:
print_r($object, false);

I asked a question related to variadic functions where the advantages of using it are explained.

But I do not know the name of this operator used in variadic funcion , that of the ... operator.

I often talk with reluctance. But I do not know if I'm right.

What is the correct name for this operator?

    
asked by anonymous 16.09.2015 / 17:55

2 answers

11

Splat (or, Scatter , or Spread ).

It is an operator to indicate that its function can have any number of parameters. This name is specific to PHP. In other languages, the name changes.

If your function has splat in the declaration and has more than one argument, splat should be the last argument.

    
16.09.2015 / 18:16
2

This type of parameter is based on a similar type in C ++ for a long time.

The name of this parameter type in C ++ is even variadic arguments : link

Nor does microsoft translate the variadic name, so the term is even used like this: link

    
16.09.2015 / 18:14