php 5.5

15
PHP 5.5 Whats New!! Presented By : Naseer Ahmad

Upload: naseer-ahmad

Post on 01-Sep-2014

247 views

Category:

Technology


0 download

DESCRIPTION

New features in php 5.5

TRANSCRIPT

Page 1: Php 5.5

PHP 5.5Whats New!!

Presented By : Naseer Ahmad

Page 2: Php 5.5

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

Performance and Memory

Page 3: Php 5.5
Page 4: Php 5.5

New Features● Finally keyword.● foreach supporting lists now.

<?php$array = [ [1, 2], [3, 4],];

foreach ($array as list($a, $b)) { echo "A: $a; B: $b\n";}

?>

Page 5: Php 5.5

New Features

● empty() supports arbitrary expression.● Class name resolution via ::class

<?phpnamespace Name\Space;class ClassName {}

echo ClassName::class; //Name\Space\ClassName

?>

Page 6: Php 5.5

New Features(Array & String Direct Referencing)

<?phpecho 'Array dereferencing: ';echo [1, 2, 3][0]; Print : Array dereferencing : 1echo "\n";

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

Page 7: Php 5.5

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

:)

Page 8: Php 5.5

New Features(Generators)

Fine for normal usageWhat if we want to abstract it?

Page 9: Php 5.5

Generators

Page 10: Php 5.5

New Features(Generators)

Simpler, lesser code

Page 11: Php 5.5

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

Php 5.5Hashing api, wrapper around crypt()No external libraries,no additional installationPASSWORD_BCRYPT hashing algorithm, 60 characters hash.Salt and Cost options.

Page 12: Php 5.5

<?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

?>

Page 13: Php 5.5

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

Page 14: Php 5.5

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.”}

?>

Page 15: Php 5.5

Referenceshttp://be1.php.net/migration55.new-featureshttp://www.sitepoint.com/generators-in-php/http://geekmonkey.org/articles/39-php-5-5-generatorshttp://blog.ircmaxell.com/2012/07/what-generators-can-do-for-you.htmlhttp://blog.asmallorange.com/2013/08/php-roadmap-performance/http://php.net/manual/en/function.password-hash.phphttp://uk1.php.net/manual/en/book.opcache.phphttps://support.cloud.engineyard.com/entries/26902267-PHP-Performance-I-Everything-You-Need-to-Know-About-OpCode-Caches