- PHP 手册
- 函数参考
- 变量与类型相关扩展
- 类/对象
- 类/对象 函数
call_user_method_array
(PHP 4 >= 4.0.5, PHP 5)
call_user_method_array — 以参数列表的数组,调用用户方法
WarningThis function was DEPRECATED in PHP 4.1.0, and REMOVED in PHP 7.0.0.
Alternatives to this function include:
- call_user_func_array()
说明
call_user_method_array ( string$method_name
, object &$obj
, array $params
) : mixed
参数
-
method_name
-
要调用的方法名称。
-
obj
-
要调用的
method_name
所在的对象 object。 -
params
-
数组形式的一组参数。
范例
Example #1 代替 call_user_method_array()
<?php
call_user_func_array(array($obj, $method_name), $params);
?>
参见
- call_user_func_array() - 调用回调函数,并把一个数组参数作为回调函数的参数
- call_user_func() - 把第一个参数作为回调函数调用
User Contributed Notes 2 notes
up down 16 wloche at hotmail dot com ¶8 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
down
-9
musaatalay dot mobile at gmail dot com ¶4 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
*/
?>
add a note
官方地址:https://www.php.net/manual/en/function.call-user-method-array.php