note 89837 deleted from function.call-user-method-array by sobak

From: Date: Fri, 02 Dec 2016 04:00:44 +0000
Subject: note 89837 deleted from function.call-user-method-array by sobak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-207928@lists.php.net to get a copy of this message
Note Submitter: brudinie at googlemail dot com ---- <?php /** * @param string $func - method name * @param object $obj - object to call method on * @param boolean|array $params - array of parameters */ function call_object_method_array($func, $obj, $params=false){ if (!method_exists($obj,$func)){ // object doesn't have function, return null return (null); } // no params so just return function if (!$params){ return ($obj->$func()); } // build eval string to execute function with parameters $pstr=''; $p=0; foreach ($params as $param){ $pstr.=$p>0 ? ', ' : ''; $pstr.='$params['.$p.']'; $p++; } $evalstr='$retval=$obj->'.$func.'('.$pstr.');'; $evalok=eval($evalstr); // if eval worked ok, return value returned by function if ($evalok){ return ($retval); } else { return (null); } return (null); } ?>

« previous php.notes (#207928) next »