Task

Invoke an object method where the name of the method to be invoked can be generated at run time.



Related tasks

 Respond to an unknown method call.
 Runtime evaluation


<?php
class Example {
  function foo($x) {
    return 42 + $x;
  }
}
 
$example = new Example();
 
$name = 'foo';
echo $example->$name(5), "\n";        // prints "47"
 
// alternately:
echo call_user_func(array($example, $name), 5), "\n";
?>