Skip to content

Instantly share code, notes, and snippets.

@jmg
Created January 12, 2012 03:06
Show Gist options
  • Save jmg/1598318 to your computer and use it in GitHub Desktop.
Save jmg/1598318 to your computer and use it in GitHub Desktop.
Proxy Dispatcher using php call_user_func_array
<?php
/**
* Proxy Dispatcher using php call_user_func_array (http://us2.php.net/manual/en/function.call-user-func-array.php)
* */
class Foo {
function bar1($arg, $arg2, $arg3, $arg4) {
return "arg: $arg, arg2: $arg2, arg3: $arg3, arg4: $arg4\n";
}
function bar2($arg, $arg2) {
return "arg: $arg, arg2: $arg2\n";
}
function bar3($arg) {
return "arg: $arg\n";
}
}
class FooWrapper {
public function __construct() {
$this->_foo = new Foo();
}
public function __call($method, $arguments) {
return call_user_func_array(array($this->_foo, $method), $arguments);
}
}
$fooWrapper = new FooWrapper();
echo $fooWrapper->bar1(1,2,3,4);
echo $fooWrapper->bar2(1,2);
echo $fooWrapper->bar3(1);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment