PHP Velho Oeste 2024

call_user_method_array

(PHP 4 >= 4.0.5, PHP 5)

call_user_method_array인수 배열로 사용자 메소드를 호출 [배제됨]

설명

mixed call_user_method_array ( string $method_name , object &$obj , array $params )
Warning

call_user_method_array() 함수는 PHP 4.1.0부터 배제되었습니다.

예제

Example #1 call_user_method_array() 대체

<?php
call_user_func_array
(array($obj$method_name), $params);
call_user_func_array(array(&$obj$method_name), $params); // PHP 4

참고

add a note add a note

User Contributed Notes 2 notes

up
17
wloche at hotmail dot com
13 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
-9
musaatalay dot mobile at gmail dot com
9 years ago
<?php

class a{

    function
b($a,$b,$c){

        echo
$a." ".$b." ".$c;
   
    }
   
    function
c(Array $a, Array $b){
   
       
print_r($a);
       
        echo
"<br />";
       
       
print_r($b);
   
    }
   
    function
cuf(Array $a, Array $b){
   
       
print_r($a);
       
        echo
"<br />";
       
       
print_r($b);
   
    }

}

$a = new a;

// ### Just String Params ###

$array = array("Musa ATALAY",":","Software Developer");

$str = NULL;

foreach(
$array AS $v){
    if(
is_string($v)){
       
$str.="'".$v."',";
    }else{
       
$str.=$v;
    }
}

$str = rtrim($str,",");

$run = "echo \$a->b(".$str.");";

echo
"<br />";

eval(
$run);

$str = NULL;

/*
OUTPUT :

Musa ATALAY : Software Developer
*/

// ### With Array Params ###

$array = array(array("Musa ATALAY",":","Software Developer"),array("Musa ATALAY",":","Software Developer"));

foreach(
$array AS $i => $v){
    if(
is_string($v)){
       
$str.="'".$v."',";
    }else{
       
$str.="\$array[".$i."],";
    }
}

$str = rtrim($str,",");

$run = "echo \$a->c(".$str.");";

echo
"<br />";

eval(
$run);

/*
OUTPUT :

Musa ATALAY : Software Developer

Musa ATALAY : Software Developer
*/

?>
To Top