note 8052 added to call_user_method

From: Date: Fri, 25 Aug 2000 09:57:29 +0000
Subject: note 8052 added to call_user_method
Groups: php.notes 
Request: Send a blank email to php-notes+get-3215@lists.php.net to get a copy of this message
Ok, I found a nice use for call_user_method(): Since there seems to be no function to test wether a method exists in an object (not class! - I don't want to check all the possible parent classes), you just call the method with @call_user_method() if you're not sure wether the method exists. If it does not, the script just contiues (if you do $obj->method(), the script will die with a fatal error if the method does not exist). 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 (#3215) next »