Unpacked, named and positional arguments are in a call…

mixed sorts of pumpkins

Unpacked, named and positional arguments are in a call… Argument spread is the three dots operator, when used with arguments. Its primary usage is simple : it stands in front of a variable, and turns an array into a list of arguments. Recently, while checking the PHP 8.1 migration guide, I realized that named arguments […]

The very useful variadic argument

Remove static variables One discreet update of PHP 8.1 is the upgrade of PHP static variables behavior in classes : Static variables in methods inheritance. Let’s review what are static variables in PHP, why they were problematic so far, and strategies to upgrade the code to remove this problem. PHP static variables While static properties […]

Move that foreach() inside the method

loops goes inside

Move that foreach() inside the method Several PHP functions work with single or multiple values. For example, array_merge(), which merges several arrays into one. Or, isset(), which checks simultaneously the existence of several variables. str_replace() and preg_replace_callback() also come to mind. This approach usually brings a bit of performance, by processing a list of arguments […]

PHP 8.0 named parameters and variadic

Named arguments and variadic in PHP 8 PHP 8.0 introduces the named arguments. This is an extension of the current positional syntax. Named arguments removes some of the limitations. It also modernizes the way methods are called with an arbitrary number of arguments, with the spread operator. Let’s see what is happening there. Quick review […]