What Is New in PHP 5.6
| Category | Key Changes |
|---|---|
| New Features | Constant scalar expressions, variadic functions, argument unpacking, exponentiation operator, __debugInfo() magic method, use function and use const |
| Improvements | GMP operator overloading, file uploads larger than 2GB, better SSL/TLS defaults |
| Deprecated | mysql_* functions, call_user_method() and call_user_method_array(), mcrypt_generic_end() |
| Security | OpenSSL improvements, default_charset option |
What new language features were introduced?
PHP 5.6 added several syntactic enhancements that make code more expressive and concise. You can now use constant scalar expressions in contexts like array keys and property declarations, which is handy for defining values based on simple calculations.
Variadic functions and argument unpacking with the ... operator simplify working with variable numbers of arguments. This replaces the old pattern of using func_get_args() and makes the intent clearer at the function signature.
// Variadic function
function sum(...$numbers) {
return array_sum($numbers);
}
// Argument unpacking
$args = [2, 3];
echo pow(2, ...$args); // 8
The exponentiation operator ** provides a shorthand for mathematical power operations. The new __debugInfo() magic method allows objects to control their output when printed with var_dump().
How did imports change with use function and use const?
PHP 5.6 extended the use keyword to support importing functions and constants from namespaces. This helps avoid writing fully qualified names repeatedly, making code less verbose.
use function Namespace\functionName;
use const Namespace\CONST_NAME;
In practice, this is a quality-of-life improvement for code organization. It encourages better structure by making it easier to use individual components from namespaces without resorting to global aliases.
What improvements were made for developers?
The GMP extension gained operator overloading, allowing you to use arithmetic operators directly on GMP objects instead of calling functions like gmp_add(). This makes mathematical code with large integers much more readable.
PHP now supports file uploads larger than 2GB, which was a longstanding limitation. The php.ini settings post_max_size and upload_max_filesize can handle values greater than 2GB.
SSL/TLS defaults were improved to enable peer verification by default and support certificate fingerprint verification. This matters because it pushes developers toward more secure out-of-the-box configurations for network operations.
What was deprecated and why?
The old mysql_* functions were officially deprecated in favor of MySQLi or PDO_MySQL. This was the final push to move developers away from the outdated extension that lacked modern features like prepared statements.
call_user_method() and call_user_method_array() were deprecated in favor of call_user_func() and call_user_func_array(). The deprecated functions were just aliases that added unnecessary complexity to the language.
mcrypt_generic_end() was deprecated in favor of mcrypt_generic_deinit(), which had a clearer name. The mcrypt extension itself was already on its way out due to better alternatives becoming available.
FAQ
Should I upgrade from PHP 5.5 to 5.6?
Yes, the upgrade is relatively smooth and brings worthwhile language improvements. The new syntax features like variadic functions and the exponentiation operator can make your code cleaner. Just be prepared to address any deprecated function usage.
How do I handle the deprecated mysql extension?
Migrate to either MySQLi or PDO_MySQL. Both offer prepared statements which are more secure. The conversion is straightforward but requires testing since the APIs are different.
What's the benefit of the exponentiation operator?
It provides a cleaner syntax for power operations. Instead of writing pow(2, 3), you can now use 2 ** 3. It's a small change that improves readability for mathematical code.
Can I really upload files larger than 2GB now?
Yes, this limitation was removed. You'll need to ensure both post_max_size and upload_max_filesize in your php.ini are set to values greater than 2GB to take advantage of this.
What does the __debugInfo() method do?
It allows objects to control which properties are shown when var_dump() is called on them. You can use it to hide sensitive data or format debug output more usefully.