I recently learned about PHP's ... token (reference the docs) which is used to support variable-length argument lists. What is the term for this token or how is it pronounced? If it doesn't have a name, is their any similar functionality in another language which has a name?
-
I don't understand what you are asking the pronunciation for? – Script47 Jun 07 '18 at 14:59
-
1From http://php.net/manual/en/migration56.new-features.php#migration56.new-features.splat - perhaps splat? – Nigel Ren Jun 07 '18 at 15:01
-
Apparently, it is the *splat*. – Script47 Jun 07 '18 at 15:01
-
The term "splat" is not referenced once in http://php.net/manual/en/functions.arguments.php, but I suppose that is as good as term as any. – user1032531 Jun 07 '18 at 15:07
-
In which case, it is known as *argument unpacking* as it is titled in the link provided by @NigelRen. – Script47 Jun 07 '18 at 15:08
-
Huh, always thought splat was *, from http://spot.colorado.edu/~sniderc/poetry/wakawaka.html – aynber Jun 07 '18 at 15:10
1 Answers
TL;DR: The tokens name is 'T_ELLIPSIS', used in a function declaration makes this function 'variadic', used when calling a function with an array holding the parameters, it's called 'argument unpacking'.
Its name is T_ELLIPSIS
, I found that out using token_get_all
and token_name
in a psysh-session:
>>> token_get_all('<?php function testit(...$a) { echo $args;}')
=> [
[
379,
"<?php ",
1,
],
....
[
391,
"...",
1,
],
....
>>> token_name(391)
=> "T_ELLIPSIS"
>>>
Edit: I understood you possibly too literally -- I thought you asked for the token-name, but given the downvote(s), I suspect you meant, how do programmers refer to it in speech and writing (apparently "splat", according to the comments)
Edit 2: Used in a function definition before the last parameter, in other languages a function defined with an ellipsis in PHP, would be called a 'variadic function':
>>> function f(...$a) { return $a; }
>>> f(1, 2, 3, 4)
=> [
1,
2,
3,
4,
]
>>>
Edit 3: Finally: If you have an array holding values you want to pass to a function, you can use ...
to achieve "Argument Unpacking"
>>> function f($a, $b, $c) { return "{$a}-{$b}-{$c}"; }
>>> f(...[1,2,3]);
=> "1-2-3"
>>>

- 1
- 1

- 6,856
- 4
- 32
- 47
-
Is that not the name of the constant defined by PHP? I think the OP is asking about the actual term for this sort of operation. – Script47 Jun 07 '18 at 15:04
-
The term "ellipsis" is also not referenced once in http://php.net/manual/en/functions.arguments.php, however, feel it better describes the functionality more than "splat" and will like use "ellipsiser" or something. Then again, splat might be more fun... Maybe mix the two words? – user1032531 Jun 07 '18 at 15:12
-
-
Just received a PHP error `PHP Fatal error: Variadic parameter cannot have a default value`. Seems like PHP uses this term as well. I appreciated your post. – user1032531 Jun 07 '18 at 18:09