我真的坚持在PHP引用。在我PROGRAMM我有类似的东西,以这样的:如何复制对象?
PROGRAMM
class Test { private $_property; function __construct($property) { $this->_property = $property; } public function setProperty($property) { $this->_property = $property; } public function getProperty() { return $this->_property; } } function doSmth(Test $var) { $newVar = new Test('test'); //I need to do something here... } $var = new Test('original'); doSmth($var); var_dump($var);
问题
我应该做些什么$newVar
变量的所有内容复制到我的$var
变量,以便在使用var_dump()
功能之后,我将能够看到它,该功能在功能doSmth()
之外。而且我不能在我的程序中使用getter和setter,因为我有很多这样的代码,并且会有很多代码。有没有可能用我的限制来解决这个问题?
UPDATE:我不能在我的功能doSmth()
返回值,我也试过__clone
,但没有任何效果。有人可以告诉我,我怎样才能做到这一点__clone()
?
尝试寻找[__clone()](http://php.net/manual/en/language.oop5.cloning.php) –