如何在PHP 5中按值复制对象/克隆对象

Cli*_*ote 0 php oop

我有这个代码:

foreach ($this->configObjects as $k=>$object)
{
   $configObject=$object;

   //Here I will make a lot of changes to $configObject, however
   // I want all those changes to be kept only to the local copy of $configObject,
   // So the next time this foreach loop is run $this->configObjects array will contain
   // a clean slate of configObject objects which don't have any traces of any 
   // earlier changes that were made to them
}
Run Code Online (Sandbox Code Playgroud)

我怎么能做到这一点?

Ant*_*nna 6

好吧,你只需克隆你的对象.