Your SlideShare is downloading. ×
What's New in PHP 5.5
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

What's New in PHP 5.5

4,710
views

Published on

Follow me on Twitter at http://www.twitter.com/cballou or checkout my startup at http://www.pop.co. …

Follow me on Twitter at http://www.twitter.com/cballou or checkout my startup at http://www.pop.co.

In this presentation we will cover the best features and additions in PHP 5.5. You can look forward to the following:

* Support for generators has been added via the yield keyword
* Usage of the new finally keyword in try-catch blocks
* An overview and examples of the new password hashing API
* The foreach control structure now supports unpacking nested arrays into separate variables via the list() construct
* empty() supports arbitrary expressions such as closures returning false
* array and string literal dereferencing
* The Zend Optimiser+ opcode cache (via the new OPcache extension)

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
4,710
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
15
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. WHAT'S NEW IN PHP 5.5 ·Corey Ballou @cballou
  • 2. GENERATORS Support for generators has been added via the yield keyword range(0, 1000000)vs. user supplied function
  • 3. EXAMPLE USAGE OF YIELD KEYWORD function getLines($filepath) { $f = fopen($filepath, 'r'); try { while ($line = fgets($f)) { yield $line; } } finally { fclose($f); } } foreach (getLines("file.txt") as $n => $line) { echo $line; }
  • 4. THE "FINALLY" KEYWORD IS FINALLY HERE Execute code ALWAYS. try { throw new Exception('hello'); } catch (Exception $e) { echo $e->getMessage(); } finally { // this code will always be run echo ', world'; }
  • 5. PASSWORD HASHING API A super easy library that uses underlying crypt library. password_get_info() password_hash() password_needs_rehash() password_verify()
  • 6. EXAMPLE OF REGISTER/LOGIN function register($username, $password) { $hash = password_hash($password, PASSWORD_BCRYPT); // save hash to database } function login($username, $password) { $hash = getHashFromDbByUsername($username); if (password_verify($password, $hash)) { // perform login (store session var) return true; } return false; }
  • 7. INCREASING PASSWORD SECURITY You can optionally supply your own salt and algorithmic cost. function register($username, $password) { $options = array('salt' => 'someRandomSalt', 'cost' => 12); $hash = password_hash($password, PASSWORD_BCRYPT, $options); // save hash to database }
  • 8. EXAMPLE OF UPGRADING YOUR HASHING ALGORITHM function login($username, $password) { $hash = getHashFromDbByUsername($username); if (password_verify($password, $hash)) { // check if hash is in updated format if (password_needs_rehash($hash, PASSWORD_BCRYPT)) { // perform update $hash = password_hash($password, PASSWORD_BCRYPT); // save new hash to database } // perform login (store session var) return true; } return false; }
  • 9. FOREACH + LIST $array = [ [1, 2], [3, 4], ]; foreach ($array as list($a, $b)) { echo "A: $a; B: $bn"; }
  • 10. ARRAY_COLUMN()FUN $people = [ [ 'firstname' => 'John', 'lastname' => 'Doe' ], [ 'firstname' => 'Jane', 'lastname' => 'Doe' ], ]; // contains [ 0 => 'John', 1 => 'Jane' ] $firstnames = array_column($people, 'firstname');
  • 11. IMPROVEMENTS TO EMPTY() function always_false() { return false; } if (empty(always_false())) { echo "Hello, world."; }
  • 12. ARRAY AND STRING LITERAL DEREFERENCING // array dereferencing echo [1, 2, 3][0]; // string dereferencing echo 'PHP'[0];
  • 13. NOW LET'S REALLY GET CRAZY... function foo() { return array(1, 2, 3); } echo foo()[2]; // prints 3 $func = function() { return array('a', 'b', 'c'); }; echo $func()[0]; // prints a
  • 14. ZEND OPTIMISER+ OPCACHE EXTENSION Not a replacement for APC/memcache(d). No user cache! Available in PHP 5.4 via install. Source available: https://github.com/zend- dev/ZendOptimizerPlus $ php -v PHP 5.4.17RC1 (cli) (built: Jun 22 2013 19:27:26) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies with Zend OPcache v7.0.2, Copyright (c) 1999-2013, by Zend Technolo gies
  • 15. SO, UH, WHAT IS AN OPCODE CACHE? Component designed to speed up performance of PHP without altering the app. Overrides PHP's default compiler callback by checking if a compiled intermediate-code version of the code is available in-memory. It skips compilation when it can!
  • 16. WHAT TO DO ABOUT DEPRECATED APC MODULE? APC User Cache is in the works: APC minus the opcode cache! github.com/krakjoe/apcu
  • 17. BACKWARDS INCOMPATIBLE CHANGES Win XP/2003 support dropped self, parent and static are case insensitive pack()and unpack()made more compatible with perl http://www.php.net/manual/en/migration55.deprecated.php
  • 18. CREDITS php.net - What has changed in PHP 5.5.x wiki.php.net - Integrating Zend Optimizer+ into the PHP distribution schlueters.de - Features in PHP trunk: Array dereferencing slideshare.net - What's new in PHP 5.5 stackoverflow.com - How do you use bcrypt for hashing passwords in PHP?
  • 19. QUESTIONS? COMMENTS? Thanks for pretending to enjoy my banter!