PHP 5.5.0 Released
Written by Ian Elliot   
Friday, 21 June 2013

PHP has come a long way since it was first released and now we have version 5.5 with some interesting sophisticated new features.

PHP 5.5 is ready for you to download and install and the source code is ready for you to read. For a decimal point upgrade there are a lot of new features. 

From the language point of view, PHP has acquired some "modern" features. You can now make use of generators to implement iteration over custom data. PHP introduces the yield command, which is familiar from other languages.

A generator is just a standard function with a yield value command in place of a return. When a generator is first called it returns an iterator which can be used in a foreach loop. When used in a foreach loop the generator function is called and returns the value specified in the yield as the value used in the loop. When the loop repeats the generator is resumed at the instruction following the yield so providing a sequence of values. 

For example:

function genseq() {
 $i=1;
 yield $i;
 $i=6;
 yield $i;
 $i=27;
 yield $i;
}

generates the sequence 1,6,27 and can be used in a foreach loop as 

$generator = genseq();
foreach ($generator as $value) {
    echo "$value\n";
}

or more simply

foreach ($genseq() as $value) {
    echo "$value\n";
}

There are a lot of other things to learn about yield and the way it can be used to create sophisticated iterative solutions and manage asynchronous calls as a form of continuation passing.

The addition of generators is by far the biggest change to the core language, but it is worth noting that PHP finally has finally.

PHP programmers have been waiting of the finally clause within exceptions for almost as long as I have been waiting to write the "finally finally" sentence. It adds a structure that has been missing from PHP for too long.  Code in a finally block is executed no matter what - i.e. irrespective of whether the code in the try block works or causes an exception. It provides an opportunity to clean up whether the code works or it fails. 

Another important change is the new password hashing API. Given how important security is, the fact that it now takes one line to create a salted password;

$hash=password_hash($password,PASSWORD_DEFAULT)'

and one line to verity it:

$bool=password_verify($password,$hash);

is a great advantage.

Crypto doesn't get any easier.

Under the cover the new API uses Bcrypt which provides a very secure hash which should keep passwords safe provided they are long enough.

There are a number of other minor additions to the language:

  • support for list() in foreach
  • constant array/string dereferencing
  • ext/intl improvement
  • support for using empty() on the result of function calls and other expressions

A big change to the operating environment is the addition of Zend Optimizer+, which was open sourced earlier in the year. This is now part of the core distribution, OPcache, and it improves the bytecode generation and caches code in shared memory. 

Of course, with any change to a language there are likely to be incompatibilities. The only ones listed are the loss of the PHP logo GUIDs whatever they were and the change to case sensitive matching. Previously this was locale-specific, but now it applies independent of locale. 

It might also affect a few users that Windows XP is no longer supported. However, there can't be many Windows XP systems acting as web servers and so the number affected should be small. 

Finally, if you hurry you have the opportunity to add the first comments to some of the PHP documentation pages, which at the time of writing look unusually bare!

 

 

phplogo

 

More Information

Announcement of 5.5.0 

New features and incompatibilities

Related Articles

Zend Optimizer+ For PHP?

PHP 5.5 Beta1 Released        

Zend Survey of PHP Developers       

 

 

 

To be informed about new articles on I Programmer, install the I Programmer Toolbar, subscribe to the RSS feed, follow us on, Twitter, FacebookGoogle+ or Linkedin,  or sign up for our weekly newsletter.

 

 

blog comments powered by Disqus

Banner


SalesForce Wave
15/10/2014

Announced at this year's Dreamforce, Wave is Salesforce’s first business intelligence and data analytics package.



MOOC On Functional Programming Using Haskell
16/10/2014

Erik Meijer's Introduction to Functional Programming MOOC has just started. If this is a topic you want to know more about, this free class could be an ideal route.


More News

 

 

 

Last Updated ( Friday, 21 June 2013 )
 
 

   
RSS feed of news items only
I Programmer News
Copyright © 2014 i-programmer.info. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.