Working with new PHP 8 operators
A number of new operators have been introduced with PHP 8. In addition, PHP 8 generally introduces a uniform and consistent manner in which these operators can be used. In this section, we examine the following operators:
- Variadics operator
- Nullsafe operator
- Concatenate operator
- Ternary operator
Let's start with a discussion of the variadics operator.
Using the variadics operator
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...