Get number of parameters a function requires

前端 未结 2 1431
误落风尘
误落风尘 2020-12-10 15:03

This is an extension question of PHP pass in $this to function outside class

And I believe this is what I\'m looking for but it\'s in python not php: Programmaticall

相关标签:
2条回答
  • 2020-12-10 15:14

    Only way is with reflection by going to http://us3.php.net/manual/en/book.reflection.php

    class foo {
     function bar ($arg1, $arg2) {
       // ...
     }
    }
    
    $method = new ReflectionMethod('foo', 'bar');
    $num = $method->getNumberOfParameters();
    
    0 讨论(0)
  • 2020-12-10 15:33

    Use Reflection, especially ReflectionFunction in your case.

    $fct = new ReflectionFunction('client_func');
    echo $fct->getNumberOfRequiredParameters();
    

    As far as I can see you will find getParameters() useful too

    0 讨论(0)
提交回复
热议问题