Migrating from PHP 5.5.x to PHP 5.6.x: Advantages & New Features
PHP 5.6.x is most commonly used PHP version and it comes tagged with some exclusive features and some backward incompatible changes for improvements.
Constant Scalar expression
It facilitates to use operations on constants or constant values
we can use it in “Constant declarations”, “Class Constant Declarations”, “Class Property Declarations”, “Argument Declarations”, “Static Variable Declarations”.
Example :
<?php const NUM=7; static $x=NUM == 9 ? "True" : "Wrong") echo $x; ?>
>/pre> Exponentiation using the ** operator
The new ** operator allows to calculate a number to the power of another number.
<?php $exp = $y ** 5 // equivalent to pow($y,5) ?>
Variadic function with argument unpacking
function sum(...$numbers) { $sum=0; foreach($numbers as $num) { $sum+=$num; } return $sum; } echo sum(1,2,3,4,5);
In this …$numbers receives the first argument as it is and the other into the $numbers array .
UTF-8
The default character encoding was set to UTF-8
Zip Improved
ZipArchive::setPassword() function which easily allows you to create password protected zip file.p
POST memory requirement
Removed the functions always_populate_raw_post_data and $HTTP_RAW_POST_DATA which reduced the usage of memory 2 to 3 times.
And getting POST via ://input is unavailable when the form is multipart.
Large File Uploads
Php 5.6.x has no restriction on size of file to be uploaded. The previous limit was 2GB.
GMP operators now supports internal operator overloading
More expressive code.
It allows polymorphism for the functions performing arithmetic operations.
With operator overloading PHP 5.6.x can work with any type of numbers.
Importing namespace function
It can be used with functions and constants.
Example : namespace abc\cba{ function fun1(){ return ‘abc.cba.fun1’; } function fun2(){ return fun1(); } } namespace{ use function abc\cba\fun1 as fun; var_dump(fun()); }
Other features
json_decode is more strict in JSON syntax parsing
While defining array as a property of a class using array literal , keys won’t be overwritten
__debugInfo() method has been added
Even though, PHP5.6.x has many added features there are backward incompatibilities like lack of support for Windows XP and 2003.