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

search for in the

call_user_method> <__autoload
[edit] Last updated: Fri, 30 Nov 2012

view this page in

call_user_method_array

(PHP 4 >= 4.0.5, PHP 5)

call_user_method_arrayWywołuje metodę użytkownika zadaną z tablicą parametrów [przestarzałe]

Opis

mixed call_user_method_array ( string $nazwa_metody , object &$obiekt , array $parametry )
Ostrzeżenie

Funkcja ccall_user_method_array() jest od PHP 4.1.0 przestarzała.

Parametry

nazwa_metody

Nazwa wywoływanej metody.

obiekt

obiekt, w którym wywoływana jest nazwa_metody.

parametry

Tablica zawierająca parametry.

Przykłady

Przykład #1 Alternatywa dla call_user_method_array()

<?php
call_user_func_array
(array($obiekt$nazwa_metody), $parametry);
call_user_func_array(array(&$obiekt$nazwa_metody), $parametry); // PHP 4
?>

Zobacz też:



call_user_method> <__autoload
[edit] Last updated: Fri, 30 Nov 2012
 
add a note add a note User Contributed Notes call_user_method_array - [3 notes]
up
1
wloche at hotmail dot com
2 years ago
You don't have to write a new function, <?php call_user_func_array(array($obj, $method_name), $params); ?> works pretty fine! (to my mind, 'eval' fucntion should be avoided almost all the time)
up
-1
brudinie at googlemail dot com
4 years ago
<?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);  
}

?>
up
-1
leonwinter at gmail dot com
6 years ago
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.

 
show source | credits | sitemap | contact | advertising | mirror sites