by Enrico Zimuel - @ezimuel
Senior Software Engineer
Zend Technologies, a Rogue Wave Company (USA)
Codemotion, Milan, 25th Nov. 2016
Released: 3 December 2015
Last major was PHP 5, 13 July 2004 (11 years!)
Last release is 7.0.13 (10 Nov 2016)
Unicode support at the core language level
Not released, project is abandoned
Version | Release | Supported until |
5.3 | 30 June 2009 | 14 August 2014 |
5.4 | 1 March 2012 | 3 September 2015 |
5.5 | 20 June 2013 | 21 July 2016 |
5.6 | 28 August 2014 | 31 December 2018 |
7.0 | 3 December 2015 | 3 December 2018 |
7.1 | December 2016? | 3 years |
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 |
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
Cryptographically secure pseudo-random number generators
// generates a random number between 1 and 100
$num = random_int(1,100);
// generates a random string of 1 Kb
$bytes = random_bytes(1024);
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
A <=> B
0 if A == B, 1 if A > B, -1 if A < B
echo 1 <=> 1; // 0
echo 1 <=> 2; // -1
echo 2 <=> 1; // 1
echo "a" <=> "a"; // 0
echo "a" <=> "b"; // -1
echo "b" <=> "a"; // 1
?? operator
// Fetches the value of $_GET['user'] and returns 'nobody'
// if it does not exist.
$username = $_GET['user'] ?? 'nobody';
// This is equivalent to:
$username = isset($_GET['user']) ? $_GET['user'] : 'nobody';
// Coalescing can be chained
$username = $_GET['user'] ?? $_POST['user'] ?? 'nobody';
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
Check the PHP 7 new features at php.net
Check the PHP 7.1 new features at php.net
Contact me: enrico.zimuel [at] roguewave.com
Blog and web site: www.zimuel.it
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.