PHP 5.6.0 was released yesterday, which marks another milestone for PHP development. With it comes a nice set of new features and a few BC breaks. I’ll go over some of the more prominent points and link to a list of everything for your deeper perusal. As for features, the most interesting to me are improved handling of variatic functions and argument unpacking with
..., constant scalar expressions, exponentiation, and file downloads that can exceed 2 GB. There are a few more, but these are, perhaps, the ones that the average developer may encounter/use on a regular basis.
So, lets get down to some examples.
Improved handling of variadic functions and Argument unpacking with
Variadic fuctions and argument unpacking are perhaps best explained through example.
We can indicate, in a function’s parameter, that we are willing to accept any number of arguments by using the
... (elipsis), which eliminates our need to rely on func_get_args().
1 2 3 4
add_these function will take any number of arguments we throw at it and within our function that
$numbers variable becomes an array that can be passed to other functions or iterated through.
The variatic function’s parameter can also be type-hinted.
1 2 3 4 5 6 7
$users is 2 User objects with a name and email property, we should see the following output.
1 2 3 4 5
Unpacking works similarly,
1 2 3 4 5 6 7 8
So, passing an array into the function with a preceding
... will use each index in the array as a different argument for the function.
Ok, a little take home for you. Consider this outout :
1 2 3 4 5 6
Constant Scalar Expressions
Typically, we’re used to constants being static values:
In PHP 5.6, you’ll be able to provide an expression for constant values:
1 2 3 4
This feature is an addition to the math operators that basically provides a shortcut (and more readable text) for working with
pow(). Essentially, if you’ve used
pow(4, 5), you could now use
4**5 instead. All pretty straight forward.
** ends up a little more concise and seems easier to scan over (to me) than the
File downloads exceeding 2 GB
With larger and more complex systems, higher resolution photos, and larger documents comes the need for larger uploads/downloads. Thank the PHP Lords for this one!
As for other goodies, go check out the PHP 5.6 page for details and examples of the other features, including GMP operator overloading, the new
hash_equals() function, bundled phpdbg, and the new magic method
__debugInfo(), to name a few. Although this is a minor update, and there only seem to be a few changes, the changes that are being made with PHP are heralding the future of PHP.
As for backward compatability, there are a few things that have be broken.
- For starters, Windows 2003 and XP are no longer supported (not too shocking).
staticare now always (lower) case sensitive.
- The PHP logo GUIDs have been removed, effecting the following functions:
1 2 3 4
- Plus, a few others
Pretty interesting changes so far, perhaps we’ll still see one more minor version before PHP 7.
We’d love to hear your comments below, so feel free to correct me, ask questions, or just rant!
Enjoy your weekend!