Possible Duplicate:
what is Object Cloning in php?
I am studying a existing framework which uses a “clone” keyword a lot, not sure whether this is a good idea to do this ? i dont really understand the need to use the ‘clone’ keyword.
for example have look at this coding
i.e
public function getStartDate ()
{
return clone $this->startDate;
}
to me this function should be like below, i dont see the need of the clone.
public function getStartDate ()
{
return $this->startDate;
}
Reason for using clone is that PHP when working with object always returns object as a reference, not as a copy.
That is why when passing object to a function you don’t need to specify it with & (reference):
So in order to get object copy you have to use clone keyword
This is an example on how objects are handled by php and what clone does: