How to get function's parameters names in PHP?

前端 未结 3 1882
情话喂你
情话喂你 2021-02-07 18:28

I\'m looking for a sort of reversed func_get_args(). I would like to find out how the parameters were named when function was defined. The reason for this is I don\

3条回答
  •  深忆病人
    2021-02-07 19:29

    Code snippet that creates an array containing parameter names as keys and parameter values as corresponding values:

    $ref = new ReflectionFunction(__FUNCTION__);
    
    $functionParameters = [];
    foreach($ref->getParameters() as $key => $currentParameter) {
        $functionParameters[$currentParameter->getName()] = func_get_arg($key);
    }
    

提交回复
热议问题