class MyClass { public function myMethod($a, $b, $c) { // do something } } $reflection = new ReflectionMethod('MyClass', 'myMethod'); if ($reflection->getNumberOfParameters() == 3) { // method requires 3 arguments }
class MyClass { public function myMethod($a, $b, $c) { // do something } } $reflection = new ReflectionMethod('MyClass', 'myMethod'); $numArgs = $reflection->getNumberOfParameters(); $args = array('arg1', 'arg2', 'arg3'); if ($numArgs == count($args)) { $obj = new MyClass(); call_user_func_array(array($obj, 'myMethod'), $args); // dynamically call method with args }The `ReflectionMethod` class is part of the PHP standard library and does not require any additional packages or libraries.