Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : Class/Object Functions : call_user_method

call_user_method

Call a user method on an specific object [deprecated] (PHP 4, PHP 5)
mixed call_user_method ( string method_name, object &obj [, mixed parameter [, mixed ...]] )


Code Examples / Notes » call_user_method

jmcastagnetto

You can pass a variable number of parameters to a function, use a definition like:
function mymethod ($v1, $v2, $v3="", $v4="")
and then you can pass 2, 3 or 4 parameters. This is explained in the "Functions" section of the manual.
See also the PHP4 functions: func_num_args(), func_get_arg(), and func_get_args(), and examples therein


jonathanmaps_on

You can also dynamically call functions through variable variables...for example:
<?php
class xyz{
  function mybar($str)
  {
    echo $str;
  }
}
$xyz = new xyz;
$foo = 'bar';
$xyz->{'my'.$foo}('dynamic call to function');
?>


paulo

This function is very similar to this:
$method="Print";
$object->$method($param1,$param2);
Note the extra $ after the ->


j dot h

It does not work to use Pointers as Arguments:
<?php
class abc{
  function func(&$argument)  {
      $argument="It works";
  }
}
$obj=new abc;
$argument_to_be_changed="No it doesnt";
call_user_method("func", $obj, $argument_to_be_changed);
echo "Result".$argument_to_be_changed;
?>
The result is: "No it doesnt".
Regards
der Jan


Change Language


Follow Navioo On Twitter
call_user_method_array
call_user_method
class_exists
get_class_methods
get_class_vars
get_class
get_declared_classes
get_declared_interfaces
get_object_vars
get_parent_class
interface_exists
is_a
is_subclass_of
method_exists
property_exists
eXTReMe Tracker