PHP 5.5
Whats New!!

Presented By : Naseer Ahmad
Performance and Memory
Performance by 10-30%
Memory by 50%
●
●

precompiled script bytecode in shared memory
reduction in loading and parsing of scripts on every request

HOW???

!! Zend Optimizer & opcode cache !!
Available in PECL for PHP versions 5.2, 5.3 and 5.4
New Features
● Finally keyword.
● foreach supporting lists now.
<?php
$array = [
[1, 2],
[3, 4],
];
foreach ($array as list($a, $b)) {
echo "A: $a; B: $bn";
}
?>
New Features
● empty() supports arbitrary expression.
● Class name resolution via ::class
<?php
namespace NameSpace;
class ClassName {}
echo ClassName::class; //NameSpaceClassName
?>
New Features(Array & String Direct Referencing)
<?php
echo 'Array dereferencing: ';
echo [1, 2, 3][0];

Print : Array dereferencing : 1

echo "n";
echo 'String dereferencing: ';
echo 'PHP'[0];
echo "n";
?>

Print : String dereferencing: P
New Features(Generators)
●
●
●
●

Routine to control the iteration of a loop
Sequence of values in loop
Values on demand
In simple words, put foreach over a function
:)
New Features(Generators)

Fine for normal usage
What if we want to abstract it?
Generators
New Features(Generators)

Simpler, lesser code
New Features(Password Hashing Api)
> Php 5.5
Relying on
● custom hash methods
● somewhat confusing crypt() method

Php 5.5
Hashing api, wrapper around crypt()
No external libraries,no additional installation
PASSWORD_BCRYPT hashing algorithm, 60 characters hash.
Salt and Cost options.
<?php
$timeTarget = 0.2;
$cost = 9;
do {
$cost++;
$start = microtime(true);
password_hash("test", PASSWORD_BCRYPT, ["cost" => $cost]);
$end = microtime(true);
} while (($end - $start) < $timeTarget);
echo "Appropriate Cost Found: " . $cost; //Appropriate Cost Found: 11
?>
New Features(Password Hashing Api)
● password_get_info — Returns information about the
given hash
● password_hash — Creates a password hash
● password_needs_rehash — Checks if the given hash
matches the given options
● password_verify — Verifies that a password matches a
hash
New Features(Password Hashing Api)
<?php
$hash = password_hash(‘MyPassword’, PASSWORD_DEFAULT);
if(password_verify(‘MyPassword’, $hash)){
echo “Password is valid!!”;
}
else{ echo “invalid password.”}
?>
References
http://be1.php.net/migration55.new-features
http://www.sitepoint.com/generators-in-php/
http://geekmonkey.org/articles/39-php-5-5-generators
http://blog.ircmaxell.com/2012/07/what-generators-can-do-for-you.html
http://blog.asmallorange.com/2013/08/php-roadmap-performance/
http://php.net/manual/en/function.password-hash.php
http://uk1.php.net/manual/en/book.opcache.php
https://support.cloud.engineyard.com/entries/26902267-PHP-Performance-IEverything-You-Need-to-Know-About-OpCode-Caches

Php 5.5