downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

call_user_method> <Klassen/Objecten functies
Last updated: Wed, 22 Jul 2009

view this page in

call_user_method_array

(PHP 4 >= 4.0.5, PHP 5)

call_user_method_array — Roept een door de programmeur gedefinieerde methode aan met een array van parameters [vervangen].

Beschrijving

mixed call_user_method_array ( string $methode_naam , object $obj [, array $paramarr ] )
Warning

De call_user_method_array() functie is reeds vervangen vanaf PHP 4.1.0. In plaats van deze functie raden we je aan de functie call_user_func_array() te gebruiken.

Deze functie roept de methode methode_naam aan op het door de programmeur definieerde object obj . Voor deze methode worden de elementen in paramarr gebruikt als parameters.

See also: call_user_func_array(), call_user_func(), call_user_method().

Note: Deze functie werd toegevoegd na de release van PHP 4.0.4pl1



add a note add a note User Contributed Notes
call_user_method_array
brudinie at googlemail dot com
25-Mar-2009 04:23
<?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);  
}

?>
leonwinter at gmail dot com
02-Oct-2006 01:45
If you this function will be deleted in future php releases you can use this function:

<?
      
function _call_user_method_array($name, $obj, $params) {
          
// get params
          
$txt = "";
           foreach(
$params as $nr => $el) {
              
$txt.='$params['.$nr."], ";
           }
          
$txt = substr($txt, 0, strlen($txt)-2);
          
// run it
          
return eval('return call_user_method($name, $obj, '.$txt.');');          
       }
?>

Hope this helps somebody.

call_user_method> <Klassen/Objecten functies
Last updated: Wed, 22 Jul 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites