Unpacked, named and positional arguments are in a call… How to handle an array of positional arguments in PHP? 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 […]
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 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 is a good place to move that foreach() inside the method. This approach […]
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 with named arguments […]