by Enrico Zimuel
Senior Software Engineer - Zend
Rogue Wave Software Inc.
Turin Web Performance Meetup, 16th May 2017
|
|

Released: 3 December 2015
Last major was PHP 5, 13 July 2004 (11 years!)
Last release is 7.1.5 (11 May 2017)
Unicode support at the core language level
Not released, project abandoned
| Version | Initial release | Active support | Security support |
| 5.6 | 28 Aug 2014 | 19 Jan 2017 | 31 Dec 2018 |
| 7.0 | 3 Dec 2015 | 3 Dec 2017 | 3 Dec 2018 |
| 7.1 | 1 Dec 2016 | 1 Dec 2018 | 1 Dec 2019 |
PHPNG, PHP Next Generation
Project by Dmitry Stogov (Zend)
New data structure management in the PHP engine
Great performance improvement!
$a = [];
for ($i = 0; $i < 1000000; $i++) {
$a[$i] = ["hello"];
}
echo memory_get_usage(true);
| PHP 5.6 | PHP 7 | |
| Memory Usage | 428 MB | 33 MB |
| Execution time | 0.49 sec | 0.06 sec |
PHP 7 is also faster than Python 3!





function foo(): array {
return [];
}
function bar(): DateTime {
return null; // invalid
}
More information: PHP documentation
declare(strict_types=1);
function sendHttpStatus(int $statusCode, string $message) {
header('HTTP/1.0 ' .$statusCode. ' ' .$message);
}
sendHttpStatus(404, "File Not Found"); // ok
sendHttpStatus("403", "OK"); // fatal error
function add(float $a, float $b): float {
return $a + $b;
}
add(1, 2); // float(3)
More information: PHP documentation
/* return an anonymous class */
return new class($controller) implements Page {
public function __construct($controller) {
/* ... */
}
/* ... */
};
class Foo {}
$child = new class extends Foo {};
var_dump($child instanceof Foo); // true
More information: PHP documentation
function hi(?string $name): ?string
{
if (null === $name) {
return null;
}
return 'Hello ' . $name;
}
echo hi(null); // returns null
echo hi('Enrico'); // returns 'Hello Enrico'
echo hi(); // Fatal error: Too few arguments to function hi(), 0 passed
function swap(&$left, &$right): void
{
if ($left === $right) {
return;
}
$tmp = $left;
$left = $right;
$right = $tmp;
}
$a = 1;
$b = 2;
var_dump(swap($a, $b), $a, $b); // null, int(2), int(1)
Throwable: Error, Exception
function call_method($obj) {
$obj->method();
}
try {
call_method(null); // oops!
} catch (Error $e) {
printf ("Error: %s\n", $e->getMessage());
} catch (Exception $e) {
printf ("Exception: %s\n", $e->getMessage());
}
More information: PHP documentation
try {
// Some code...
} catch (ExceptionType1 $e) {
// Code to handle the exception
} catch (ExceptionType2 $e) {
// Same code to handle the exception
} catch (Exception $e) {
// ...
}
try {
// Some code...
} catch (ExceptionType1 | ExceptionType2 $e) {
// Code to handle the exception
} catch (\Exception $e) {
// ...
}

Contact me: enrico.zimuel [at] roguewave.com
Follow me: @ezimuel

This work is licensed under a
Creative Commons Attribution-ShareAlike 3.0 Unported License.
I used reveal.js to make this presentation.