Page 1 of 1

PHP 4 vs PHP 5

Posted: Sat Nov 25, 2006 3:54 am
by akreider
I notice you've got seperate versions for php 4 and 5. I'm wondering if it is possible to have the same version run on both, perhaps at the price of sacrificing some functionality (all the new fancy stuff with php 5)?

I'm trying to test out php 5 (more specifically 5.2) and to see if I can get my project to work on both. My project depends on your's and several others.

I'd like to avoid having to offer seperate versions of my software for 4 and 5, because I don't think I need the new functionality from 5.

Does your php 4 version work fine on php 5?

Posted: Sat Nov 25, 2006 5:39 am
by Maugrim_The_Reaper
In general, PHP4 code is compatible with PHP5+ with the exception of a few small items. I doubt the PHP4 version has any issues running under PHP5, though PHP5 may complain a little if you are coding under E_STRICT.

Posted: Sat Nov 25, 2006 5:58 am
by Chris Corbyn
There's no way I'll ever drop the PHP5 branch. It's little effort to me to develop under PHP5 and then quickly "translate" that the PHP4 before releasing. PHP5 will run PHP4 code and it should run the PHP4 branch of swift just fine. But it will not run well under E_STRICT. Not long after PHP6 is released I need to consider whether to deprecate the PHP4 version or maintain 3 version because (if they ever implement it!) I'd like to take full advantage of namespacing to clean things up a little.

Just use the PHP4 version, but don't expect it run work without warning or notices on all servers ;)

Posted: Tue Nov 28, 2006 1:28 am
by AKA Panama Jack
Actually, you CAN write PHP 4 code and classes that will not show any errors under E_STRICT settings when running under PHP 5. Personally I am not going to create PHP 5 only versions of my projects because it really isn't needed for the most part.

The E_STRICT error from the use of VAR in classes was removed in PHP Version 5.1.3 back in May. So you can create 100% PHP 4 code that doesn't throw any E_STRICT errors in PHP. This way you can have one branch that works on PHP 4 and PHP 5 without E_STRICT errors. I was glad they finally fixed the VAR oversight.

Posted: Tue Nov 28, 2006 4:13 am
by Chris Corbyn
AKA Panama Jack wrote:Actually, you CAN write PHP 4 code and classes that will not show any errors under E_STRICT settings when running under PHP 5. Personally I am not going to create PHP 5 only versions of my projects because it really isn't needed for the most part.

The E_STRICT error from the use of VAR in classes was removed in PHP Version 5.1.3 back in May. So you can create 100% PHP 4 code that doesn't throw any E_STRICT errors in PHP. This way you can have one branch that works on PHP 4 and PHP 5 without E_STRICT errors. I was glad they finally fixed the VAR oversight.
I use interfaces, abstract classes, exceptions, static class members. Interfaces and abstract classes come in extremely useful when you're writing a pluggable system. I know I can get by without them but those features exist in OOP for a reason :) I'm developing in PHP5 and "stripping down" to PHP4. It involves doing things like, where I'd throw an exception in PHP5 I'll return a negative value in PHP4. That negative value corresponds to an "error type" and a getErrorMessage() method allows you to see the message which would be in an exception in PHP5. It's not overly desirable but I'd rather work this way than write code which doesn't take advantage of the more mature OOP capabilities in PHP5. PHP6 will be out before we know it so it would be a shame to have fallen two versions behind come that time too :) I'm also planning to make a Java release (sssshh, don't tell anyone) so this may feel a little Java-esque. It also appears to be a "selling point" of this library from some of the emails I receive. People like using code in PHP5 which was specifically written for PHP5.