Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Foo
- {
- public function bar()
- {
- $argsCount = func_num_args();
- switch ($argsCount) {
- case 1:
- return $this->_barWithOneArgument(func_get_arg(0));
- break;
- case 2:
- return $this->_barWithTwoArguments(func_get_arg(0), func_get_args(1));
- break;
- default:
- throw new InvalidArgumentException();
- }
- }
- private function _barWithOneArgument($a)
- {
- return "Hello, I'm one argument function";
- }
- private function _barWithTwoArguments($a, $b)
- {
- return "Hello, I'm function with two arguments";
- }
- }
- $foo = new Foo();
- var_dump($foo->bar(1));
- var_dump($foo->bar(1, 2));
Advertisement
Add Comment
Please, Sign In to add comment