Posted on: 2019/9/12 2:44
Re: xoopsClone issues
There are not a lot of examples for xoopsClone() that I can find.
Assuming $existingObject is a child of XoopsObject
$newObject = $existingObject->xoopsClone();
will create a cloned copy of $existingObject.
It is probably wise to instead use PHP's clone like this:
$newObject = clone $existingObject;
It is possible that an object with custom properties might not produce a proper clone with xoopsClone(), while the PHP clone
would clone any custom properties.
The clone, in either case, has all the vars copied, and is set as a new object.
One potential problem is that the XoopsObject has no internal knowledge of it's primary key, so while the object is marked new, it still has any auto-increment PK set. You can work around this issue by doing a $newObject->destroyVars('key-variable-name'); to clean up after a clone.
It probably would have made more sense for a xoopsClone() method to be in the handler rather than the object, but this choice was made a long time ago.