A Brave New ‘Hello World’
Last week IBM’s developerWorks ran an article about The Future of PHP about the upcoming PHP 5.3 and 6.0 releases. While the new features in PHP6 may be underwhelming in terms of sheer quantity, the release marks a major milestone for PHP: Unicode support. Since Unicode recently surpassed other character encodings on the web, having every PHP function support Unicode will greatly improve the ease at which content may be managed within an application. There are numerous other efficiencies and optimizations added as most of PHP’s built-in functions have been overhauled, which should increase performance for existing code, as well.
What’s in a name(space)?
The biggest gain in PHP’s upcoming releases, however, is the addition of namespaces to the object model. Because class names must be unique, we’ve previously had to use naming conventions as workarounds to avoid naming collisions (which could be common when you include third-party class libraries), writing classes named such as:
class DuoConsulting_WebService_Xml_Parser
With namespaces, you can specify a namespace to keep class names shorter and saner:
namespace DuoConsulting::WebService::Xml;
class Parser
{
...
}
Then when you use these objects the code is more readable and less error prone. You can also use aliases to assign a shorter keyword to a long namespace:
use DuoConsulting::WebService::Xml as xml;
$parser = new xml::Parser();
You can read more about the PHP 5.3 implementation of namespaces in the CVS repository.
What’s Missing?
Nearly all of the features that have been removed in PHP6 were already deprecated in PHP5, which means you probably shouldn’t have been using them for the past three years anyway. Most PHP5-only code (such as the Zend Framework) should require no modifications, whereas some code ported from an older PHP4 codebase may need to be updated to run in PHP6. Since it was bad practice to use the vast majority of removed features even in PHP4 (such as <code>register_globals</code> which automatically created new variables based on GET and POST parameters such as those passed through a URL or web form) their removal should only reinforce better coding practices rather than break existing applications.
The near future looks bright for PHP, and since the biggest changes to the language are going to be coming in the next major point release, I suspect it may not be long before 5.3 is the de facto minimal version under which a number of applications will run.


Thanks Jough!
Leave a Reply