Durian: a PHP 5.5 microframework with generator-style middleware
What's new in PHP 5.5
-
Upload
tom-corrigan -
Category
Technology
-
view
17.218 -
download
0
description
Transcript of What's new in PHP 5.5
![Page 1: What's new in PHP 5.5](https://reader031.fdocuments.net/reader031/viewer/2022020206/54899b74b4795984178b55a7/html5/thumbnails/1.jpg)
What’s new in PHP 5.5Tom Corrigan
@thetommygnrMelbourne PHP Users Group
May 2013
Wednesday, 22 May 13
![Page 2: What's new in PHP 5.5](https://reader031.fdocuments.net/reader031/viewer/2022020206/54899b74b4795984178b55a7/html5/thumbnails/2.jpg)
Overview
• What’s new
• What’s gone
• What’s deprecated
• Current status of PHP 5.5
Wednesday, 22 May 13
![Page 3: What's new in PHP 5.5](https://reader031.fdocuments.net/reader031/viewer/2022020206/54899b74b4795984178b55a7/html5/thumbnails/3.jpg)
Generators
• Syntactical sugar to avoid iterator boilerplate
• Introduce a new keyword yield
• https://wiki.php.net/rfc/generators
Wednesday, 22 May 13
![Page 4: What's new in PHP 5.5](https://reader031.fdocuments.net/reader031/viewer/2022020206/54899b74b4795984178b55a7/html5/thumbnails/4.jpg)
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
![Page 5: What's new in PHP 5.5](https://reader031.fdocuments.net/reader031/viewer/2022020206/54899b74b4795984178b55a7/html5/thumbnails/5.jpg)
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
![Page 6: What's new in PHP 5.5](https://reader031.fdocuments.net/reader031/viewer/2022020206/54899b74b4795984178b55a7/html5/thumbnails/6.jpg)
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
![Page 7: What's new in PHP 5.5](https://reader031.fdocuments.net/reader031/viewer/2022020206/54899b74b4795984178b55a7/html5/thumbnails/7.jpg)
Generators - my opinion
• Few use cases
• Every example I found demonstrated the functionality rather than its utility
• More readable alternatives
Wednesday, 22 May 13
![Page 8: What's new in PHP 5.5](https://reader031.fdocuments.net/reader031/viewer/2022020206/54899b74b4795984178b55a7/html5/thumbnails/8.jpg)
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/finally
Wednesday, 22 May 13
![Page 9: What's new in PHP 5.5](https://reader031.fdocuments.net/reader031/viewer/2022020206/54899b74b4795984178b55a7/html5/thumbnails/9.jpg)
The problem:
$db = mysqli_connect();try { call_some_function($db); //function may throw exceptions which we can ‘t handle} catch (Exception $e) { mysqli_close($db); throw $e;}mysql_close($db);
Wednesday, 22 May 13
![Page 10: What's new in PHP 5.5](https://reader031.fdocuments.net/reader031/viewer/2022020206/54899b74b4795984178b55a7/html5/thumbnails/10.jpg)
Finally: a solution
$db = mysqli_connect();try { call_some_function($db);//function may throw exceptions which we can ‘t handle} finally { mysqli_close($db);}
Wednesday, 22 May 13
![Page 11: What's new in PHP 5.5](https://reader031.fdocuments.net/reader031/viewer/2022020206/54899b74b4795984178b55a7/html5/thumbnails/11.jpg)
Finally block is always executed
try { return 2;} finally { echo "this will be called\n";}//this will never be calledecho "you can not see me";
this will be called//return int(2)
Wednesday, 22 May 13
![Page 12: What's new in PHP 5.5](https://reader031.fdocuments.net/reader031/viewer/2022020206/54899b74b4795984178b55a7/html5/thumbnails/12.jpg)
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, between 5%-20% faster than APC
• https://wiki.php.net/rfc/optimizerplus
Wednesday, 22 May 13
![Page 13: What's new in PHP 5.5](https://reader031.fdocuments.net/reader031/viewer/2022020206/54899b74b4795984178b55a7/html5/thumbnails/13.jpg)
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
![Page 14: What's new in PHP 5.5](https://reader031.fdocuments.net/reader031/viewer/2022020206/54899b74b4795984178b55a7/html5/thumbnails/14.jpg)
APCu
• APC without the bytecode cache (userland caching only)
• PHP API maintains BC with APC
• https://github.com/krakjoe/apcu
Wednesday, 22 May 13
![Page 15: What's new in PHP 5.5](https://reader031.fdocuments.net/reader031/viewer/2022020206/54899b74b4795984178b55a7/html5/thumbnails/15.jpg)
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
![Page 16: What's new in PHP 5.5](https://reader031.fdocuments.net/reader031/viewer/2022020206/54899b74b4795984178b55a7/html5/thumbnails/16.jpg)
Constant array and string dereferencing
You can now do this:
echo [“one”, “two”, “three”][1];=> “two”
And this:
echo “onetwothree”[1];=> “n”
Wednesday, 22 May 13
![Page 17: What's new in PHP 5.5](https://reader031.fdocuments.net/reader031/viewer/2022020206/54899b74b4795984178b55a7/html5/thumbnails/17.jpg)
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
![Page 18: What's new in PHP 5.5](https://reader031.fdocuments.net/reader031/viewer/2022020206/54899b74b4795984178b55a7/html5/thumbnails/18.jpg)
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_column
Wednesday, 22 May 13
![Page 19: What's new in PHP 5.5](https://reader031.fdocuments.net/reader031/viewer/2022020206/54899b74b4795984178b55a7/html5/thumbnails/19.jpg)
Password hash
• Colby did a talk last month
• Use it today in PHP 5.3.7+ https://github.com/ircmaxell/password_compat
Wednesday, 22 May 13
![Page 20: What's new in PHP 5.5](https://reader031.fdocuments.net/reader031/viewer/2022020206/54899b74b4795984178b55a7/html5/thumbnails/20.jpg)
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.php
Wednesday, 22 May 13
![Page 21: What's new in PHP 5.5](https://reader031.fdocuments.net/reader031/viewer/2022020206/54899b74b4795984178b55a7/html5/thumbnails/21.jpg)
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.php
Wednesday, 22 May 13
![Page 22: What's new in PHP 5.5](https://reader031.fdocuments.net/reader031/viewer/2022020206/54899b74b4795984178b55a7/html5/thumbnails/22.jpg)
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.php
Wednesday, 22 May 13
![Page 23: What's new in PHP 5.5](https://reader031.fdocuments.net/reader031/viewer/2022020206/54899b74b4795984178b55a7/html5/thumbnails/23.jpg)
Current status
• First Release Candidate: 9 May
• Second RC due out on 23rd May
• Expected stable release soon
Wednesday, 22 May 13
![Page 24: What's new in PHP 5.5](https://reader031.fdocuments.net/reader031/viewer/2022020206/54899b74b4795984178b55a7/html5/thumbnails/24.jpg)
Questions?
Wednesday, 22 May 13