Web developers are pleasantly surprised to know about the latest advancement embracing PHP. Recently PHP 5.5.0 was released and it comes with a bundle of high-end features as well as some much needed bug fixes.
In the all new PHP 5.5.0, web developers can watch out for three striking developments and improvements to have graced the PHP 5.5.0. Before talking about the enhancements, one striking difference to understand before you upgrade the PHP to 5.5.0 is that it will no longer support Windows 2003 as well as Windows XP.
We have Got Generators!!
The first major improvement comes in the form of generators, which were not previously available. With the help of these generators, web developers will now find it easy to repeat the data searching process without the need to write down a class that implements the Iterator interface.
Similar to all other functions in the PHP, generators will be identified with their function keyword. However, generators are different from the normal functions which will provide the result only once. With the generator, the developer can derive any number of results, simply with the usage of the yield keyword. With the help of a foreach loop integrated in the generators, the web developer can iterate over a huge set of data. The developer does not have to additionally create an array in the system memory. With this, the developer not just saves memory space but also cuts down the processing time.
For instance, the web developer can use the range () function for creating a sequence ranging between one and one million. He can name this range as (0, 1000000) in the foreach loop. With this, he will be creating an array that features a memory capacity of more than 100 MB. This is stated in the PHP manual. Compared to the huge amount of memory space created, he will be only requiring close to 1 KB to create the sequence with the help of a generator function.
Now Exception is Easy and “Finally”
Another important enhancement in the PHP 5.5.0 is the addition of the “finally” keyword. With the inclusion of ‘finally’ keyword, PHP gets a whole new way of how it works with exception handling. Similar to high-level scripting languages, PHP lets the web developer wrap the code in a secure try and catch block. Any exception that the code throws within the realm of the try block will be transferred to the code that is secured in the catch block for effective handling.
With the ‘finally’ keyword, the web developer can easily define any block of code which needs to be placed right after catch block. The block of code will be executed always after the execution of the try and catch blocks. This is not subjective to an exception.
Another striking improvement in the PHP 5.5.0 is the all new password hashing API. With this, the web developer can use a single line of code for generating salted password hash with the help of bcrypt. Though bcrypt is the present encryption algorithm by default, it will undergo changes as new and more reliable algorithms are introduced in the PHP.