What’s new in PHP 5.5Tom Corrigan@thetommygnrMelbourne PHP Users GroupMay 2013Wednesday, 22 May 13
Overview• What’s new• What’s gone• What’s deprecated• Current status of PHP 5.5Wednesday, 22 May 13
Generators• Syntactical sugar to avoid iterator boilerplate• Introduce a new keyword yield• https://wiki.php.net/rfc/gener...
Before generatorsfunction getLinesFromFile($fileName) {if (!$fileHandle = fopen($fileName, r)) {return;} $lines = [];while...
Generator in actionfunction getLinesFromFile($fileName) {if (!$fileHandle = fopen($fileName, r)) {return;} while (false !=...
Generator free approachfunction doShit($filename){if (!$fileHandle = fopen($fileName, r)) {return;} while (false !== $line...
Generators - my opinion• Few use cases• Every example I found demonstrated the functionality rather than itsutility• More ...
Finally• New addition to try...catch blocks• Code within a finally block will always be executed. Always!• Useful for closi...
The problem:$db = mysqli_connect();try {call_some_function($db); //function may throw exceptions which we can ‘thandle} ca...
Finally: a solution$db = mysqli_connect();try {call_some_function($db);//function may throw exceptions which we can ‘thand...
Finally block is always executedtry {return 2;} finally {echo "this will be calledn";}//this will never be calledecho "you...
Opcache• Zend Optimizer+ has been open sourced and renamed Opcache• Included by default in PHP 5.5+• This is a big win, it...
What about APC?• No current plans to support PHP > 5.4• Does it matter?• Was always behind new PHP releases by months• Opc...
APCu• APC without the bytecode cache (userland caching only)• PHP API maintains BC with APC• https://github.com/krakjoe/ap...
DateTimeImmutable• DateTime$dt = new DateTime(‘2013-05-21’);$dt2 = $dt->modify(‘+1 day’);echo $dt->format(‘Y-m-d’); //2013...
Constant array and stringdereferencingYou can now do this:echo [“one”, “two”, “three”][1];=> “two”And this:echo “onetwothr...
list() inside foreach$talks = [["speaker" => "Tom Corrigan","talk" => "What’s new in PHP 5.5",],["speaker" => "Rick Measha...
array_column()$talks = [["speaker" => "Tom Corrigan","talk" => "What’s new in PHP 5.5",],["speaker" => "Rick Measham","tal...
Password hash• Colby did a talk last month• Use it today in PHP 5.3.7+ https://github.com/ircmaxell/password_compatWednesd...
Tons of new stuff in ext/intl• Didn’t get time to cover this one, sorry!• See: http://www.php.net/manual/en/migration55.cl...
Removed/changed• No Windows XP or 2003 support• Case insensitivity no longer locale specific• Logo functions removed: php_l...
Deprecated• ext/mysql !!!!• preg_replace() /e modifier, use preg_replace_callback() (good!)• IntlDateFormatter::setTimeZone...
Current status• First Release Candidate: 9 May• Second RC due out on 23rd May• Expected stable release soonWednesday, 22 M...
Questions?Wednesday, 22 May 13
Upcoming SlideShare
Loading in …5
×

What's new in PHP 5.5

18,687 views
18,430 views

Published on

Published in: Technology
3 Comments
7 Likes
Statistics
Notes
  • that you, it's a nice presentation on new features of PHP 5.5 but I feel a bit of sadness that windows XP support is going away (70% of people still depend on it). Like to share it on OSIpage, http://www.osipage.com
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • For such a use case there is an even better, more readable and obvious approach.
    for ($i = 0; $i lte 1000000; $i++) {
    //do something with $i
    }

    I wrote a more detailed reply, twice! but slideshare's stupid html filter truncated everything after a less than sign, hence lte = less than or equal in the code block. I can't be bothered typing out my full response again so let me summarise by saying I am yet to see a real world (not trivial demo code) usage of generators where there was not another approach that was preferable in terms of readability, LOC or performance.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • The use case for generators is actually significant if you have an application where memory is a concern. Since they essentially wrap the functionality of extending Iterator, they are very very memory efficient. In a generator function, they only use memory for the current yield array indice as it's being iterated over in foreach. The savings is huge. Comparing range(0, 1000000) to a comparable generator approach, we're talking about using 100MB of memory vs a fraction of kilobyte.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
18,687
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
45
Comments
3
Likes
7
Embeds 0
No embeds

No notes for slide

What's new in PHP 5.5

  1. 1. What’s new in PHP 5.5Tom Corrigan@thetommygnrMelbourne PHP Users GroupMay 2013Wednesday, 22 May 13
  2. 2. Overview• What’s new• What’s gone• What’s deprecated• Current status of PHP 5.5Wednesday, 22 May 13
  3. 3. Generators• Syntactical sugar to avoid iterator boilerplate• Introduce a new keyword yield• https://wiki.php.net/rfc/generatorsWednesday, 22 May 13
  4. 4. Before generatorsfunction getLinesFromFile($fileName) {if (!$fileHandle = fopen($fileName, r)) {return;} $lines = [];while (false !== $line = fgets($fileHandle)) {$lines[] = $line;} fclose($fileHandle); return $lines;} $lines = getLinesFromFile($fileName);foreach ($lines as $line) {// do something with $line}Wednesday, 22 May 13
  5. 5. Generator in actionfunction getLinesFromFile($fileName) {if (!$fileHandle = fopen($fileName, r)) {return;} while (false !== $line = fgets($fileHandle)) {yield $line;} fclose($fileHandle);} $lines = getLinesFromFile($fileName);foreach ($lines as $line) {// do something with $line}Wednesday, 22 May 13
  6. 6. Generator free approachfunction doShit($filename){if (!$fileHandle = fopen($fileName, r)) {return;} while (false !== $line = fgets($fileHandle)) {// do something with $line} fclose($fileHandle);}Wednesday, 22 May 13
  7. 7. Generators - my opinion• Few use cases• Every example I found demonstrated the functionality rather than itsutility• More readable alternativesWednesday, 22 May 13
  8. 8. Finally• New addition to try...catch blocks• Code within a finally block will always be executed. Always!• Useful for closing DB connections, file handles etc• https://wiki.php.net/rfc/finallyWednesday, 22 May 13
  9. 9. The problem:$db = mysqli_connect();try {call_some_function($db); //function may throw exceptions which we can ‘thandle} catch (Exception $e) {mysqli_close($db);throw $e;}mysql_close($db);Wednesday, 22 May 13
  10. 10. Finally: a solution$db = mysqli_connect();try {call_some_function($db);//function may throw exceptions which we can ‘thandle} finally {mysqli_close($db);}Wednesday, 22 May 13
  11. 11. Finally block is always executedtry {return 2;} finally {echo "this will be calledn";}//this will never be calledecho "you can not see me";this will be called//return int(2)Wednesday, 22 May 13
  12. 12. Opcache• Zend Optimizer+ has been open sourced and renamed Opcache• Included by default in PHP 5.5+• This is a big win, it’s the fastest opcode cache for PHP, between5%-20% faster than APC• https://wiki.php.net/rfc/optimizerplusWednesday, 22 May 13
  13. 13. What about APC?• No current plans to support PHP > 5.4• Does it matter?• Was always behind new PHP releases by months• Opcache is faster• Opcaches ships with PHP 5.5+Wednesday, 22 May 13
  14. 14. APCu• APC without the bytecode cache (userland caching only)• PHP API maintains BC with APC• https://github.com/krakjoe/apcuWednesday, 22 May 13
  15. 15. DateTimeImmutable• DateTime$dt = new DateTime(‘2013-05-21’);$dt2 = $dt->modify(‘+1 day’);echo $dt->format(‘Y-m-d’); //2013-5-22echo $dt2->format(‘Y-m-d’); //2013-5-22• DateTimeImmutable$dt = new DateTimeImmutable(‘2013-05-21’);$dt2 = $dt->modify(‘+1 day’);echo $dt->format(‘Y-m-d’); //2013-5-21echo $dt2->format(‘Y-m-d’); //2013-5-22• Warning: Extends DateTime, type hints won’t save youWednesday, 22 May 13
  16. 16. Constant array and stringdereferencingYou can now do this:echo [“one”, “two”, “three”][1];=> “two”And this:echo “onetwothree”[1];=> “n”Wednesday, 22 May 13
  17. 17. list() inside foreach$talks = [["speaker" => "Tom Corrigan","talk" => "What’s new in PHP 5.5",],["speaker" => "Rick Measham","talk" => "Hacker tips for getting hired",],];foreach ($talks as list($speaker, $talk){echo $speaker. " on " . $talk . PHP_EOL;}// Tom Corrigan on What’s new in PHP 5.5// Rick Measham on Hacker tips for getting hired•https://wiki.php.net/rfc/foreachlistWednesday, 22 May 13
  18. 18. array_column()$talks = [["speaker" => "Tom Corrigan","talk" => "What’s new in PHP 5.5",],["speaker" => "Rick Measham","talk" => "Hacker tips for getting hired",],];$speakers = array_column($talks, "speaker");//array[0] Tom Corrigan[1] Rick Measham• https://wiki.php.net/rfc/array_columnWednesday, 22 May 13
  19. 19. Password hash• Colby did a talk last month• Use it today in PHP 5.3.7+ https://github.com/ircmaxell/password_compatWednesday, 22 May 13
  20. 20. Tons of new stuff in ext/intl• Didn’t get time to cover this one, sorry!• See: http://www.php.net/manual/en/migration55.classes.phpWednesday, 22 May 13
  21. 21. Removed/changed• No Windows XP or 2003 support• Case insensitivity no longer locale specific• Logo functions removed: php_logo_guid(), php_egg_logo_guid() etc• Changes to pack() and unpack() BC BREAK• http://www.php.net/manual/en/migration55.incompatible.phpWednesday, 22 May 13
  22. 22. Deprecated• ext/mysql !!!!• preg_replace() /e modifier, use preg_replace_callback() (good!)• IntlDateFormatter::setTimeZoneID() and datefmt_set_timezone_id()• some mcrypt functions• http://www.php.net/manual/en/migration55.deprecated.phpWednesday, 22 May 13
  23. 23. Current status• First Release Candidate: 9 May• Second RC due out on 23rd May• Expected stable release soonWednesday, 22 May 13
  24. 24. Questions?Wednesday, 22 May 13

×