Saturday, March 24, 2007

Method overloading

mixed __call ( string name, array arguments )

Class methods can be overloaded to run custom code defined in your class by defining this specially named method. The $name parameter used is the name as the function name that was requested to be used. The arguments that were passed in the function will be defined as an array in the $arguments parameter. The value returned from the __call() method will be returned to the caller of the method.

class Caller
private $x = array(1, 3, 5, 7, 9);

private function __call($func, $args)
echo "call missing method: {$func}<br>";
echo "<pre>";
echo "</pre>";
return $this->x;

$c = new Caller();
$rs = $c->test(1, 3, 'test', 'array', 'args');

No comments :