|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2003-09-07 17:15 UTC] sniper@php.net
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 00:00:02 2025 UTC |
Description: ------------ You *must* use Call-time pass-by-reference to pass a object-reference when using call_user_function. In the example changeA() is declared to use passing by reference but it still doesn't work. I think call_user_function should either try to discover if it's passing by reference at runtime or just pass always by reference. Reproduce code: --------------- <?php class A { var $_id = 'A'; function printID() { print "A::id=[".$this->_id."]\n"; } function remote(&$obj_ref, $obj_method) { call_user_func(array(&$obj_ref, $obj_method), $this); // this on works: // call_user_func(array(&$obj_ref, $obj_method),&$this); } } class B { function changeA(&$obj) { $obj->_id = 'B'; $obj->printID(); } } $a = new A(); $b = new B(); $a->printID(); $a->remote($b, 'changeA'); $a->printID(); ?> Expected result: ---------------- A::id=[A] A::id=[B] A::id=[B] Actual result: -------------- A::id=[A] A::id=[B] A::id=[A]