PHP Cloning

group of baby dollsPHP version 5 object oriented capabilities are quite different from PHP version 4. What would be ideal is that we write our PHP code without knowing what the underlying technology is. As PHP 4 does not contain a cloning method, what we can do is create our own clone method thus allowing our PHP 4 and 5 code to work consistently:

if (version_compare(phpversion(), '5.0') < 0) { if (!function_exists('clone')) { eval(' function clone($object) { return $object; } '); } }

To clone an object in PHP 4 and 5 just do:

$newObject = clone($object);

Add the above code to your PHP library and your code will be more robust and work in all versions of PHP. The aboving PHP cloning method also creates a consistency within your client code.