Community Update

PHP Göteborg Meetup #5 - 2016-10-06

Rickard Bennison

PHP 5.6

Active support ends 31 Dec 2016 😱

Two more years of security patches

Version 7.0

Almost one year old! 🎉

One more year of active support

Two more years of security patches

Version 7.1

Release Candidate 3

To be released in November

Nullable types

function testReturn(): ?string
{
    return 'elePHPant';
}

function test(?string $name)
{
    var_dump($name);
}

Void functions

function swap(&$left, &$right) : void
{
    if ($left === $right) {
        return;
    }

    $tmp = $left;
    $left = $right;
    $right = $tmp;
}

Symmetric array destructuring

$data = [[1, 'Tom'], [2, 'Fred']];

// list() style
list($id1, $name1) = $data[0];

// [] style
[$id1, $name1] = $data[0];

// list() style
foreach ($data as list($id, $name)) {
    // logic here with $id and $name
}

// [] style
foreach ($data as [$id, $name]) {
    // logic here with $id and $name
}

Class constant visibility

class ConstDemo
{
    const PUBLIC_CONST_A = 1;
    public const PUBLIC_CONST_B = 2;
    protected const PROTECTED_CONST = 3;
    private const PRIVATE_CONST = 4;
}

iterable pseudo-type

function iterator(iterable $iter)
{
    foreach ($iter as $val) {
        //
    }
}

Multi catch exception handling

try {
    // some code
} catch (FirstException | SecondException $e) {
    // handle first and second exceptions
}

Support for keys in list()

$data = ["id" => 1, "name" => 'Tom'];

// list() style
list("id" => $id, "name" => $name) = $data;

// [] style
["id" => $id, "name" => $name] = $data;

Support for negative string offsets

var_dump("abcdef"[-2]);
var_dump(strpos("aabbcc", "b", -3));

👍

  • Support for AEAD in ext/openssl
  • Convert callables to Closures with Closure::fromCallable()
  • Asynchronous signal handling
  • HTTP/2 server push support in ext/curl

@rickard2

https://about.me/rickard2
www.montania.se
https://phpse.stamplayapp.com/