The first PHP 5.3 release candidate hit the mirrors today. Here’s a quick rundown of the main features of this release:
Namespaces – As your PHP scripts grow larger and more complex, it can be difficult to keep track of which variables you’re using. This is worsened if you’re using additional libraries and scripts from other sources that you didn’t write yourself. PHP’s new namespaces aim to alleviate the problem by allowing you to group your variables into categories. No more hours spent trying to find which bit of code is overwriting your variables.
Late Static Binding – Here’s the problem, how do create a class that accesses method / properties that haven’t been initialised yet. Admittedly, a tough one without the use of late static bindings. Creating a class, you can access the properties and methods in that class using the self:: keyword. If you create a child that extends that class you can access the parent’s properties and methods using the parent:: keyword. But until now, you’ve been unable to access the child’s properties and methods from the parent class. This is because multiple children can be used to instantiate the parent. Late static bindings means that in addition to self:: and parent::, the static:: keyword now provides access to all parent and instantiating child properties / methods. Happy days!
Anonymous / Lambda Functions – graduates of Java and other object-orientated program will recognise this immediately. It’s the ability to create a function (for example, as a callback function), without having to give it a name. When a function requires a callback, rather than having to define a function and enter that name as the callback we can use the standard function() {} syntax to group a few statements together on-the-fly.
Native MySQL Library – the PHP team have written their own MySQL library for the 5.3 release. This new “native library” is under the same license terms as the PHP project, not MySQL AB’s license terms. This means MySQL support can now be bundled in the PHP by default. Being developed specifically to work with PHP has also lead to greater memory efficiency.
Phar – clean out your PHP directories and organise your applications that bit more by grouping them into Phars. Similar to Java’s Jar files, you can distribute entire apps in a compressed form. PHP will now recognise the phar::// URI scheme, so that you can include individual files from a Phar archive without extracting all the files.