What's new in PHP

PHPers, Katowice, 11 September 2014

Michał Pipa

About me

Who is still using PHP 5.2?

Release process

PHP 5.3: end of life

Last release: 5.3.29

PHP 5.4: security fixes only

Released: 1 March 2012

PHP 5.5

Released: 20 June 2013

PHP 5.6

Released: 28 August 2014

PHP 5.7

Next 5.x release

PHP next: PHP 7

Wait, what about PHP 6?

PHP 6 was abandoned in March 2010

PHP 6 = PHP 5.3 + unicode

unicode = PHP 6 - PHP 5.3

3v4l.org

Online PHP & HHVM shell, execute code in 100+ different versions!

New features

PHP 5.5: Generators

Generators provide an easy, boilerplate-free way of implementing iterators.

PHP 5.5: Generators


function getLinesFromFile($fileName) {
    if (!$fileHandle = fopen($fileName, 'r')) {
        return;
    }
 
    while (false !== $line = fgets($fileHandle)) {
        yield $line;
    }
 
    fclose($fileHandle);
}
 
$lines = getLinesFromFile($fileName);
foreach ($lines as $line) {
    // do something with $line
}

PHP 5.5: Simple password hashing

  • md5() and sha1() are unsuitable for passwords
  • password_hash() and password_verify()
  • example output: $2y$12$QjSH496pcT5CEbzjD/vtVeH03tfHKFy36d4J0Ltp3lRtee9HDxY3K
  • Userland implementation for PHP >= 5.3.7

PHP 5.5: Class name resolution as scalar via "class" keyword


use A\Namespaced\ClassName;
 
// ClassName::class resolves to 'A\Namespaced\ClassName'
$mock = $this->getMock(ClassName::class);

PHP 5.5: "finally" keyword


$db = mysqli_connect();

try {
   call_some_function($db);
} catch (Exception $e) {
   mysqli_close($db);
   throw $e;
}

mysql_close($db);

PHP 5.5: "finally" keyword


$db = mysqli_connect();

try {
   call_some_function($db);
} finally {
   mysqli_close($db);
}

PHP 5.5: Zend Opcache extension

PHP 5.6: Exponential operator

2 ** 3

PHP 5.6: phpdbg

  • phpdbg is a gdb-like PHP debugger
  • Implemented as a SAPI module
  • Flexible breakpoints
  • Disassembly of PHP Code
  • Remote debugging

PHP 5.6: Variadic functions


class MySQL implements DB {
    public function query($query, ...$params) {
        $stmt = $this-&pdo-&prepare($query);
        $stmt-&execute($params);
        return $stmt;
    }
}

PHP 5.6: TLS Peer Verification

PHP 5.6: Uploads equal or greater than 2GB in size are now accepted

PHP 5.7: Integer division

3 %% 2

PHP 7

  • phpng
  • 64 bit platform improvements for string length and integer
  • Abstract syntax tree
  • Uniform variable syntax

Alternative PHP implementations

HHVM

  • Virtual machine (not a compiler anymore)
  • Uses a just-in-time (JIT) compilation
  • Hack language
    • High performance
    • Type annotations
    • Generics
    • Collections
    • Lambdas

PHP specification

Hippyvm

HippyVM is an implementation of the PHP language using PyPy technology

Thank you

Questions?