BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News PHP 5.6 Released

PHP 5.6 Released

This item in japanese

Lire ce contenu en français

Bookmarks

The PHP development team announced the availability of PHP 5.6. The new release brings new features and many improvements, the PHP development team say, as well as some backward incompatible changes.

Among the most significant changes in this release:

  • Constant scalar expressions

    It is now allowed to use basic arithmetic and logical operators in constant declarations, functions default arguments, and class properties:

    const ONE = 1;
    const TWO = ONE * 2;
    
    class C {
    const THREE = TWO + 1;
    const ONE_THIRD = ONE / self::THREE;
    const SENTENCE = 'The value of THREE is '.self::THREE;
    
    public function f($a = ONE + self::THREE) {
        return $a;
        }
    }
    
  • Improved syntax for variadic functions

    Variadic functions can be declared through a new ... operator:

     
    public function variadic_function($param, ...$paramsArray) {
         // method implementation
    }
    

    In the above syntax, ...$paramsArray tells the interpreter to put all the variadic arguments into the $paramsArray array, which can then be used as such in the method implementation. Previously, variadic arguments could be bundled into an array by calling:

    $paramsArray = array_slice(func_get_args(), 1)
    
  • Exponentiation

    The new ** operator allows to calculate a number to the power of another number.

  • UTF-8

    The default character encoding has been set to UTF-8.

  • GMP operator overloading

    GMP objects now support operator overloading and casting to scalar types. This allows for more expressive code using GMP:

    $a = gmp_init(42);
    $b = gmp_init(17);
    
    // Pre-5.6 code:
    var_dump(gmp_add($a, $b));
    var_dump(gmp_add($a, 17));
    var_dump(gmp_add(42, $b));
    
    // New code:
    var_dump($a + $b);
    var_dump($a + 17);
    var_dump(42 + $b);
         
  • Large file uploads

The previous limit of 2GB on file uploads has been removed and uploads of arbitrary size are now supported.

For users upgrading from PHP 5.5, a migration guide is available, detailing the changes between 5.5 and 5.6.0 and complementing them with a simple demo of many new features.

PHP 5.6.0 also introduces changes that affect compatibility:

  • Array keys won't be overwritten when defining an array as a property of a class via an array literal.

  • json_decode() is more strict in JSON syntax parsing.

  • Stream wrappers now verify peer certificates and host names by default when using SSL/TLS.

  • GMP resources are now objects.

  • Mcrypt functions now require valid keys and IVs.

A full list of all changes can be additionally found in the ChangeLog.

Rate this Article

Adoption
Style

BT