garry27 Posted January 27, 2009 Share Posted January 27, 2009 I know it's possible to do a method call from one object to another and pass a new object of the calling class to the recieving class as a method parameter. But is it possible to send a copy of the calling object so that it retains the same properties? Link to comment https://forums.phpfreaks.com/topic/142644-copying-class-objects/ Share on other sites More sharing options...
rhodesa Posted January 27, 2009 Share Posted January 27, 2009 i don't 100% understand what you mean...but i will say that objects are always passed by reference...so: function foobar ( $obj ) { $obj->test = 'New Value'; } $a = new A(); $a->test = 'Old Value'; foobar($a); print $a->test; //Prints 'New Value' Link to comment https://forums.phpfreaks.com/topic/142644-copying-class-objects/#findComment-747641 Share on other sites More sharing options...
garry27 Posted January 27, 2009 Author Share Posted January 27, 2009 ok, I have a class callsed 'form' which handles/manages all the html forms stuff (or at least it will once I've repaired it). Inside a 'form' instance , I want to recreate this same instance (with whatever state it may be at the time) so that I can send it to another object. Link to comment https://forums.phpfreaks.com/topic/142644-copying-class-objects/#findComment-747652 Share on other sites More sharing options...
rhodesa Posted January 27, 2009 Share Posted January 27, 2009 um, don't you just want to use $this? <?php class form { function doit ( ) { $fb = new foobar(); $fb->test($this); } } class foobar { function test ( $form ) { print $form->test; } } $f = new form(); $f->test = 'some value'; $f->doit(); ?> Link to comment https://forums.phpfreaks.com/topic/142644-copying-class-objects/#findComment-747659 Share on other sites More sharing options...
garry27 Posted January 27, 2009 Author Share Posted January 27, 2009 thanks! I'll give that a try. I saw the $this command used in a different context but wasn't sure. Link to comment https://forums.phpfreaks.com/topic/142644-copying-class-objects/#findComment-747667 Share on other sites More sharing options...
rhodesa Posted January 27, 2009 Share Posted January 27, 2009 thanks! I'll give that a try. I saw the $this command used in a different context but wasn't sure. omg...$this is the core of OOP. it refers to the current object Link to comment https://forums.phpfreaks.com/topic/142644-copying-class-objects/#findComment-747670 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.