Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Lorna Mitchell:
PHP 5.6 and the Splat Operator
Mar 17, 2014 @ 14:05:36

Lorna Mitchell has a new post to her site looking at a feature of the upcoming PHP 5.6 release, the splat operator (three ellipsis...).

We have a couple of new features coming in to PHP 5.6 with names that sound much less exciting than the features they actually represent: "variadic functions" sound positively academic, and "argument unpacking" isn't exactly catchy. However they both use a new operator in PHP which looks like an elipsis (three dots ...) and is referred to as either the splat operator or the scatter operator. I included them in a recent version of my "Upgrading PHP" talk so I thought I'd share the examples here too in case anyone is interested.

She includes an example of it being used in a variadic function, one that lets you define an optional number of parameters without having to resort to func_get_args. She also talks about "argument unpacking" or the passing in of an array of values with the splat to have it handled like a string. An example with the mail function is included.

tagged: php56 splat operator variadic function argument unpacking

Link: http://www.lornajane.net/posts/2014/php-5-6-and-the-splat-operator

Phil Sturgeon:
Potential Variadic Function Syntax for PHP 5.6
Sep 03, 2013 @ 16:55:37

Phil Sturgeon has another post to his site about a recently proposed RFC for PHP. This time it's about implementing a variadic function syntax in the language. This kind of handling would allow for a variable number of parameters on a function/method and not having to use func_get_args to pull in the list.

An awesome RFC popped up the other day: Syntax for variadic functions, developed by Nikita Popov. I read through it and I loved it, but I did have to Google to see what the hell a variadic function was. This is what happens when you teach yourself how to code. You know how to do things, but don't know any of the words. Variadic functions are already possible in PHP and have been throughout 4.x and 5.x in the form of func_get_args(), which is pretty gross.

He includes an example of how it would work and some of the pros and cons of implementing it in the language including:

  • Type hinting (pro)
  • Argument unpacking (con)
  • Easier documentation in docblocks (pro)
  • Keeping up with the "Joneses" (con)
tagged: variadic function syntax rfc proposal

Link: http://philsturgeon.co.uk/blog/2013/08/potential-variadic-function-syntax-for-php-56


Trending Topics: