note 8052 deleted from function.call-user-method by didou
| From: | didou@php.net | Date: | Fri, 22 Aug 2003 11:11:57 +0000 |
| Subject: | note 8052 deleted from function.call-user-method by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-54863@lists.php.net to get a copy of this message | ||
Note Submitter: bachi@insign.ch
----
[Editor's note: There is a function to test for the existence of a particular method:
method_exists().
The function described here should be used when generating programatically generic calls to object
methods, akin to lambda function calls for example]
Ok, I found a nice use for call_user_method():
BUT: There's a strange limitation here: In this example, the $a property won't increase as
expected when $t->increase() is called with call_user_method(). Strange!
class test
{
var $a=0;
function increase()
{
$this->a++;
echo "a is now: ".$this->a."\n<br>";
}
}
$t = new test();
echo "Direct calls:\n<br>";
$t->increase();
$t->increase();
$t->increase();
echo "<p>\n\nIndirect calls:\n<br>";
call_user_method ("increase", $t);
call_user_method ("increase", $t);
call_user_method ("increase", $t);