getting function's argument names

后端 未结 6 985
清歌不尽
清歌不尽 2020-12-08 04:13

In PHP Consider this function:

function test($name, $age) {}

I need to somehow extract the parameter names (for generating custom documenta

6条回答
  •  不知归路
    2020-12-08 04:50

    It's 2019 and no one said this?

    Just use get_defined_vars():

    class Foo {
      public function bar($a, $b) {
        var_dump(get_defined_vars());
      }
    }
    
    (new Foo)->bar('first', 'second');
    

    Result:

    array(2) {
      ["a"]=>
      string(5) "first"
      ["b"]=>
      string(6) "second"
    }
    

提交回复
热议问题