Changes in v*prinf(), NULL Length Arguments, and the implode() Function
Learn about the updated print methods and other features in PHP 8.
Dealing with v*printf() changes
The v*printf() family of functions is a subset of the printf() family of functions that includes vprintf(), vfprintf(), and vsprintf(). The difference between this subset and the main family is that the v*printf() functions are designed to accept an array as an argument rather than an unlimited series of arguments. Here is a simple example that illustrates the difference:
Let’s get into the code.
Lines 3–9: First, we define a set of arguments that will be inserted into a pattern,
$patt.Line 13: We then execute a
printf()statement using a series of arguments.Lines 17–21: We then define the arguments as an array,
$arr, and usevprintf()to produce the same result.
In either version of PHP, the output is the same.
As we can see, the output of both functions is identical. The only usage difference is that vprintf() accepts the parameters in the form of an array.
Prior versions of PHP allowed a developer to play fast and loose with arguments presented to the v*printf() family of functions. In PHP 8, the data type of the arguments is now strictly enforced. This only presents a problem where code controls do not exist to ensure that an array is ...