hno Posted March 1, 2009 Share Posted March 1, 2009 HI what is the advantage of using _clone in a class and what does it do? Could you give a example of usage of that. And in What situations we should use that? tnx Quote Link to comment https://forums.phpfreaks.com/topic/147447-question-about-_clone/ Share on other sites More sharing options...
cooldude832 Posted March 1, 2009 Share Posted March 1, 2009 http://php.net/clone Might help you out Quote Link to comment https://forums.phpfreaks.com/topic/147447-question-about-_clone/#findComment-773925 Share on other sites More sharing options...
a-scripts.com Posted March 1, 2009 Share Posted March 1, 2009 Clone does exactly what the name says. It takes an object and creates the exact copy of it. When dealing with objects you have to keep in mind all variable passing is done by reference. $objOne = new StdClass(); $objOne->name = "Object One"; $objTwo = $objOne; $objTwo->name = "Object Two"; Now the name property of both variables is "Object Two". This won't happen if you use clone method. Note when some of the objects properties are also objects you need to clone these as well to get fresh new ones. Quote Link to comment https://forums.phpfreaks.com/topic/147447-question-about-_clone/#findComment-773929 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.