note 8052 modified in call_user_method by ronabop

From: Date: Sat, 18 Nov 2000 04:56:36 +0000
Subject: note 8052 modified in call_user_method by ronabop
Groups: php.notes 
Request: Send a blank email to php-notes+get-7851@lists.php.net to get a copy of this message
[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); http://www.php.net/manual/function.call-user-method.php

« previous php.notes (#7851) next »