Performance Improvements
✔ Generators
<?php
function xrange($start, $end) {
for ($i = $start; $i <= $end; $i ++) {
yield $i;
}
}
foreach (xrange(0, 5) as $i) {
echo $i, "\n";
}
✔ Coroutines
<?php
function logger($fileName) {
$fileHandle = fopen($fileName, 'a');
while (true) {
fwrite($fileHandle, yield . "\n");
}
}
$logger = logger(__DIR__ . '/log');
$logger->send('Foo');
$logger->send('Bar');
For an advanced explanation of coroutines, read this article by Nikita Popov
✔ finally
<?php
$db = mysqli_connect();
try {
call_some_function($db);
} finally {
mysqli_close($db);
}
✔ list() in foreach
<?php
$names = [ ['John','Smith'], ['Fred','Johnson'] ];
foreach($names as list($first,$last)) {
echo $first,$last;
}
✔ Const array/string Dereferencing
<?php
echo array(1, 2, 3)[0]; //output 1
echo "foobar"[3]; //output b
echo [1,3,4][2]; //output 4
✔ empty() support for functions/expressions
✔ curl upload functionality rewritten
✔ Simplified password hashing API
<?php
// Hash
$hash = password_hash("super secret",PASSWORD_BCRYPT);
// To validate $pwd against the stored hash
if (password_verify($pwd, $hash)) {
echo 'Password is valid!';
} else {
echo 'Invalid password.';
}