PHP 7.1 in 10 minutes

Ian Littman / @iansltx

NomadPHP EU Lightning Talks / December 2016

http://ian.im/nom7110m

PHP 7.1 is out!

Nullable Types

function get(?int $id) : ?MyObject {
    // return either a MyObject or null
}

ArgumentCountError?!?

  • When too few arguments are passed to a call
  • Used to be a Warning
  • Is now an Error (catchable)
  • If your code has this issue, 7.1 is a BC break for you

Class Constant Visibility

class MyObject
{
    protected const SECRET = "yoloswag";
}

Void Return Types

function executeAThing() : void
{
    // doesn't return anything
}

Short List Syntax

[$a, $b, $c] = returnsAnArray();

foreach (arrayOfArrays() as [$first, $second]) {}

iterable pseudo-type

function doAThingOnASet(iterable $set)
{
    // foreach over a thing
    // array or Traversable
}

Gotta catch 'em all

try {
    // do something risky
} catch (BadThing | BlackSwanEvent $e) {
    // handle these exception types
}

Closure::fromCallable()

$strlenIsNowAClosure = 
    Closure::fromCallable('strlen');

...and more!

  • Async pcntl handling
  • HTTP/2 Server Push support in cURL
  • AEAD in OpenSSL
  • Negative string offset support in more places
  • Edge case cleanup
  • ...and more!