If I'm building a PHP system which I expect to port to many different servers, should I avoid relying on PHP 5 features such as exceptions and final methods? How widespread is PHP 5 by now? Should I be worried about compatibility and ditch exceptions and other features not available in PHP 4?
views:
105answers:
5Is it a bad idea to rely on PHP 5 features when writing an application you expect to be portable?
It's definitely not a bad idea. PHP5 is much better than PHP4, it has better suport for OOP and references and it is available on the market for quite a long time. If you rely on PHP4 because of compatibility issues, then why not rely on PHP 1.0? ;)
BTW you can write portable code with version checks but in my opinion it is completely redundant at this time. PHP5 is a hard ground standard.
This depends on what type of servers that you expect to port to.
If you're looking at military contractors that are still using 486's because that's the last thing that was approved for shuttle missions, then, yes, you should use old software.
If you're considering hosted servers, the latest rev of whatever you're using will be available. If you are reselling a product to customers, you will be able to tell them what the system requirements are - OS, DB, scripting language and version, etc.
A lot of OSS fanboys will tell you two different arguments: avoid any proprietary extensions to anything because it harms portability, and 2) use the latest rev available. These are diametrically opposed points of view.
The reality is that in the web development world, I try not to let these types of debates keep me from developing using the best tools available. The one exception is browser compatibility, which is one thing that we don't have control over.
Should you ever run into somebody who wants the software to run on their PHP 4, the strongest argument is the support cycle. PHP4 is ten years old, and will not be supported very long any more (although I haven't been able to find out from the PHP web site how long exactly.)
PHP4 is actually no longer supported. Only "old" distributions and installations will support it. All major Linux distributions only support PHP5 in their latest releases.
To still offer support for PHP4 would be a bad strategy for new applications.
The page at http://php.net/archive/2007.php clearly states that PHP 4 is no longer supported since august 2008. (Php 4 end of life announcement) (look at the news published in 2008 to see the last maintenance release, published on august 7, 2008)
From the announcment in 2007, but certainly from the end of security support, I think new applications should no longer be developed for php 4, unless explicitly requested by the customer (allthough I would rather advice the customer to change his mind on that requirement). Keeping support for PHP 4 in older applications may be a bit different.