One of the noce features of PHP 5 is the ability to "clone" an object - to "create a copy of an object where properties that are references to other variables, will remain references and the _clone() method, if defined, will be run". Well, over on Dynamically Typed they just might have a way for those of you out there still working with PHP 4 to "clone" your objects.
Steven Wittens from Acko.net describes a way of implementing a clone function in PHP4 to emulate PHP5's clone behaviour.
The idea is to write object-oriented programs that will behave the same way in both PHP4 and PHP5. Obviously, the drawback of doing so is that you cannot take advantage of PHP5-only features, such as object destructor methods. But if you accept the limitations, you can still write code for PHP4 that works on PHP5, but there are a few important snags. PHP5's treatment of objects and references is one of those snags.
While it's not true cloning, this method can be quite useful when you need multiple copies of an object. Two drawbacks, however - one, it's not a true "copy" of the object, but merely a reference to it, and two, it relies on eval() to get the job done (and, let's all say it together: 'if eval is the answer, you're asking the wrong question...'). So, he offers an alternative - a method using something called a "conditional include". (It works by basically defining the close() function as a user-defined method when the PHP version is less than 5.)




