note 39280 modified in function.call-user-func by danbrown

From: Date: Sat, 19 Jul 2008 21:14:04 +0000
Subject: note 39280 modified in function.call-user-func by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-141747@lists.php.net to get a copy of this message
I was trying to use this function to call a method of an already-instantiated object. I needed to do this with the object itself, not simply call the class' method. To accomplish this, I really avoided this particular function altogether like this: <?php if ( method_exists($my_obj, $action) ){ return $my_obj->{$action}(); } ?> I hope someone else finds this useful. Note that doing this allows you to pass params to the function more-or-less in the same way you would to any other class method. --was-- I was trying to use this function to call a method of an already-instantiated object. I needed to do this with the object itself, not simply call the class' method. To accomplish this, I really avoided this particular function altogether like this: <? if ( method_exists($my_obj, $action) ){ return $my_obj->{$action}(); } ?> I hope someone else finds this useful. Note that doing this allows you to pass params to the function more-or-less in the same way you would to any other class method. http://php.net/manual/en/function.call-user-func.php

« previous php.notes (#141747) next »