Get number of parameters a function requires

前端 未结 2 1441
误落风尘
误落风尘 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();
    

提交回复
热议问题