0

I would like to get the name (not the value) of a paramter. In the given case it should be $param.

function testfunc($param = 'i do not want this..', $array = array()) {
    $args = func_get_args();
    var_dump($args);
    echo $param; 
}

If I call the testfunc like this:

testfunc($testString,$testArray);  

the result should be "$testString" ,"$testArray"

Is there a way in PHP?

hamburger
  • 1,339
  • 4
  • 20
  • 41
  • This is not duplicated. Thats something else here. – hamburger Jan 17 '23 at 14:56
  • The duplicates return the parameter names declared in the function signature. https://3v4l.org/oY24M If you want to ignore the signature declarations and access the passed in variable names, why not pass them in as single quote wrapped strings? `'$testString'` and `'$testArray'`? What are you trying to achieve with this task? – mickmackusa Jan 23 '23 at 19:59

1 Answers1

3

Use reflection

$myParams =  array_map( function( $parameter ) { return $parameter->name; }, (new ReflectionFunction(__FUNCTION__))->getParameters() );

Thanks

AVRajan
  • 106
  • 7