PHP 5.4

Performance Improvements


✔ Built-in Web Server


✔ Traits aka Horizontal Code Reuse

        (Compiler-assisted Copy-and-Paste)


✔ Short Array Syntax

<?php
$a = [1, 2, 3];
$b = ['foo' => 'orange', 'bar' => 'apple'];

✔ Function Array Dereferencing

<?php
function fruits() {
  return array('apple', 'banana', 'orange');
}
echo fruits()[0]; // Outputs: apple
?>

✔ $this from current scope supported in Closures

<?php
class Foo {
  private $prop = "bar";
  public function getPrinter() {
    return function() { echo ucfirst($this->prop); };
  }
}

$a = new Foo;
$func = $a->getPrinter();
$func(); // Outputs: Bar
?>

✔ <?= is now always available


✔ New Session Object


✔ Callable Typehint


✔ Better support for asian chars in htmlspecialchars/htmlentities


✔ Multibyte support is now configurable at runtime


✔ JSON Improvements

<?php
class Foo implements JsonSerializable {
    private $data = 'Bar';
    public function jsonSerialize() {
        return array('data'=>$this->data);
    }
}
echo json_encode(new Foo); // Outputs: {"data":"Bar"}

✔ mysqlnd used by default everywhere


✔ iterator support added to mysqli (mysqli_result implements Traversable)


✔ Binary notation

<?php
$mask = 0b010101;

✔ AES Support added to OpenSSL


✔ Tokyo Cabinet and DB5 support added to dba


✔ Added stack frame count arg to debug_backtrace()


✔ $_SERVER['REQUEST_TIME_FLOAT'] added


✔ Apache 2.4 support on Windows