PHP 5.6.0 alpha released

The PHP development team announces the immediate availability of PHP 5.6.0alpha1. This release marks the beginning of the PHP 5.6.0 release cycle. All users of PHP are encouraged to test this version carefully, and report any bugs in the bug tracking system.

THIS IS A DEVELOPMENT PREVIEW – DO NOT USE IT IN PRODUCTION!

PHP 5.6.0alpha1 comes with new features such as (incomplete list) :

1. Constant Scalar Expressions

It is now possible to provide a scalar expression involving numeric and string literals and/or constants in contexts where PHP previously expected a static value, such as constant and property declarations and default function arguments.

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 3';

        public function f($a = ONE + self::THREE) {
            return $a;
        }
    }

    echo (new C)->f()."\n";
    echo C::SENTENCE;

The above example will output:

4
    The value of THREE is 3

2. Variadic Functions

Variadic functions can now be implemented using the … operator, instead of relying on func_get_args().

function f($req, $opt = null, ...$params) {
        // $params is an array containing the remaining arguments.
        printf('$req: %d; $opt: %d; number of params: %d'."\n",
               $req, $opt, count($params));
    }

    f(1);
    f(1, 2);
    f(1, 2, 3);
    f(1, 2, 3, 4);
    f(1, 2, 3, 4, 5);

The above example will output:

$req: 1; $opt: 0; number of params: 0
    $req: 1; $opt: 2; number of params: 0
    $req: 1; $opt: 2; number of params: 1
    $req: 1; $opt: 2; number of params: 2
    $req: 1; $opt: 2; number of params: 3

3. Argument Unpacking

Arrays and Traversable objects can be unpacked into argument lists when calling functions by using the … operator. This is also known as the splat operator in other languages, including Ruby.

function add($a, $b, $c) {
        return $a + $b + $c;
    }

    $operators = [2, 3];
    echo add(1, ...$operators);

The above example will output:

6

4. use function and use const

The use operator has been extended to support importing functions and constants in addition to classes. This is achieved via the use function and use const constructs, respectively.

namespace Name\Space {
        const FOO = 42;
        function f() { echo __FUNCTION__."\n"; }
    }

    namespace {
        use const Name\Space\FOO;
        use function Name\Space\f;

        echo FOO."\n";
        f();
    }

5. A new command line debugger called phpdbg

PHP now includes an interactive debugger called phpdbg implemented as a SAPI module. For more information, please visit the » phpdbg documentation.

6. php://input is reusable

php://input may now be reopened and read as many times as required. This work has also resulted in a major reduction in the amount of memory required to deal with POST data.

7. Support for large(>2GiB) file uploads

Files larger than 2 gigabytes in size are now accepted

8. GMP supports 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);

9. gost-crypto hash algorithm

The gost-crypto hash algorithm has been added. This implements the GOST hash function using the CryptoPro S-box tables as specified by » RFC 4357, section 11.2.

10. SSL/TLS improvements

The OpenSSL extension has been extended to include support for extracting and verifying certificate fingerprints. openssl_x509_fingerprint() has been added to extract a fingerprint from an X.509 certificate, and two SSL stream context options have been added: capture_peer_cert to capture the peer's X.509 certificate, and peer_fingerprint to assert that the peer's certificate should match the given fingerprint.

Additionally, a specific crypto method such as SSLv3 or TLS may now be selected by setting the crypto_method SSL stream context option. Possible options include STREAM_CRYPTO_METHOD_SSLv2_CLIENT, STREAM_CRYPTO_METHOD_SSLv3_CLIENT, STREAM_CRYPTO_METHOD_SSLv23_CLIENT (the default), or STREAM_CRYPTO_METHOD_TLS_CLIENT.

References