Re: object pass by reference and call_user_func problems
| From: | Oliver Heinisch | Date: | Tue, 11 Jul 2000 18:48:41 +0000 |
| Subject: | Re: object pass by reference and call_user_func problems | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-5981@lists.php.net to get a copy of this message | ||
At 09:37 11.07.00 -0700, you wrote:
The problem is the $object properties don't get modified. I do the following: 1. in a function I create a new $object 2. in the same function I pass the $object to another function (func2) using call_usr_func. (func2 is actually a property of $obj that I set so it needs to be called by call_usr_func) 3. func2 accepts this $object by reference 4. func2 calls one of $objects methods that modifies the $object's properties 5. I exit out of func2 and print the $object properties but they haven't changed <? class Beetle{ var $color; } function func1(){ $obj = new Beetle(); call_user_func("func2", $obj);// if I get rid of call_user_func, or pass &$obj it worksTRY $this -> func2($obj);
print "$obj->color";// print nothing } function func2(&$obj){ $obj->color = "black";And here $this -> color= "black"; $this ->func1();
} ?> As stated in the comment if I don't use call_user_func() (not an option) it works. Or if I pass by reference &$obj (deprecated) it works. Does anybody know what's going on?But I must say, I really don´t know what this should do X-( these are just suggestions. g´s Oliver PS Send me a mail if i´m right