Variadics Operator

Learn about the variadics operator and how it helps the developer to provide multiple arguments without specifying the names of variables.

The variadics operator consists of three leading dots () preceding a normal PHP variable (or object property). This operator has actually been with the language since PHP 5.6. It’s also referred to as the following:

  • Splat operator

  • Scatter operator

  • Spread operator

Before we dive into the improvements PHP 8 has made using this operator, let’s have a quick look at how the operator is normally used.

Unknown number of arguments

One of the most common uses for the variadics operator is in a situation where we define a function with an unknown number of arguments.

In the following code example, the multiVardump() function is able to accept any number of variables. It then concatenates the var_export() output and returns a string:

Get hands-on with 1200+ tech skills courses.