lostnucleus Posted April 27, 2009 Share Posted April 27, 2009 for e.g if class test1 implements __toString so $obj1 = new test1(); echo $obj1; //works fine now consider a class test2 there is a method called setdata inside it public functio setdata($data) { $this->_data = $data; } when i do $obj2 = new test2(); $obj2->setdata($obj1); I got an error saying the passed variable to function setData is an object and connot be converted into the string ?? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted April 27, 2009 Share Posted April 27, 2009 I think we're going to need to see your source code. This, for example, works fine for me: <?php class class1{ function __toString(){ return "Some string representation"; } } class class2{ private $data; function setData($s){ $this->data = $s; } function getData(){ return $this->data; } } $foo = new class1(); echo $foo."\n"; $bar = new class2(); $bar->setData($foo); echo $bar->getData()."\n"; ?> Quote Link to comment 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.