PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I'm porting some code from PHP 4 to PHP 5. It's not liking this:
$s = _SESSION['x'];
$this = unserialize($s);
The reason I'm doing this is to have a class method called "LoadFromSession". If you have a better way to do this, please tell me.
In general, (in PHP5) I would like to be able to copy over the contents of the current object. Is there a way to assign a new object to the current object (pointed to by $this)? For eg:
Right, you need to use the clone keyword to actually copy an object. But, I want a way to copy an object into the current object.
If this were C++, I want to do this:
*this = object;
I'm a bit confused as to why you'd want to copy an object into an existing object, this would in effect overwrite it, so why not just use __clone to copy the object into a variable hence creating a copy of the object. I'm not sure why you need an existing object to copy into ?
I suppose the real question is, when do you ever need a copy of an object?