call_user_method_array
(PHP 4 >= 4.0.5, PHP 5)
call_user_method_array — Call a user method given with an array of parameters [deprecated]
Description
Warning
The call_user_method_array() function is deprecated as of PHP 4.1.0.
Parameters
-
method_name
-
The method name being called.
-
obj
-
The object that
method_name
is being called on. -
params
-
An array of parameters.
Examples
Example #1 call_user_method_array() alternative
<?php
call_user_func_array(array($obj, $method_name), $params);
call_user_func_array(array(&$obj, $method_name), $params); // PHP 4
?>
See Also
- call_user_func_array() - Call a callback with an array of parameters
- call_user_func() - Call the callback given by the first parameter
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения, относящиеся к переменным и типам
- Функции работы с классами и объектами
- __autoload
- call_user_method_array
- call_user_method
- class_alias
- class_exists
- get_called_class
- get_class_methods
- get_class_vars
- get_class
- get_declared_classes
- get_declared_interfaces
- get_declared_traits
- get_object_vars
- get_parent_class
- interface_exists
- is_a
- is_subclass_of
- method_exists
- property_exists
- trait_exists
Коментарии
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)
<?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
*/
?>