08/08/2008 was certainly not another Y2K-like event, but it is the End-of-Life (EOL) date for PHP4. For those of you wondering exactly what EOL means, it is the day when support ends for a product. This alone should propel any pragmatic programmer (redundant, I know) to move into the brave new world of PHP5. The latest release for PHP5 is version 5.2.6, released back in May. While PHP5 is designed to be backwards-compatible with PHP4, it does cause some minor issues with scripts written for PHP4. This is because PHP continues to trend away from the use of wicked little things such as register_globals – which it will phase out entirely with the introduction of PHP6, already in development (and fairly close to going public, I might add).
Are you convinced that the time has arrived to move from PHP4 to PHP5, yet? If not:
Brief Overview of Changes From PHP4 to PHP5
- New in PHP5, all objects are now passed by reference. You absolutely must clone an object now. Please also note that you can cease using the reference operator (&) to get around that pesky pass-by-value functionality.
- PHP now has three levels of visibility for class methods and properties. Public is readable by everyone, Protected makes members only accessible by parent and sub classes, and Private makes members only available to the class itself.
- The abstract class can now be declared – this new class is purely used to define a model where other classes extend.
- Class Constants and Static Method/Properties are now available.
- Unified Constructors and Destructors (__construct() and __destruct(), respectively) now allow for proper construction and destruction.
- Common APIs now can use Interfaces.
- “Magic Methods” now introduce some handy features – probably best just to look at the list.
- You can now employ the final keyword to block a child from overwriting a method.
- The __autoload function now allows for automatic loading of object files when a class has yet to be encountered.
- New SPL functions.
- Type-hinting which means that you can control what variables are passed to functions or class methods, but only currently in classes or arrays.
- PHP introduces exceptions (finally)!
- The E_Strict Error Level will now let you know when you used depreciated code.
The above is a very basic and quick overview, I always recommend going to the manual for more information! On top of all of that, PHP5 brings many new functions to the table. On top of this are the new extensions: SimpleXML, DOM, XSL, PDO, Hash.
Again, I recommend checking up on the backwards compatibility information, as this will help you identify where you are probably going to have problems. Some major catches include array_merge(), which will only allow arrays now, and get_() now returns names as defined, making get_class() case sensitive.
The change from PHP4 to PHP5 is not all that painful. You can arm yourself with the knowledge necessary to make it virtually painless. PHP is just like the internet. It is constantly evolving and you will be left in the dust. With PHP6 already on the horizon, do you really want to be using an unsupported and exploitable language in this day and age?
Make the switch and enjoy the benefits of PHP5!