How to get the number of parameter with their name of a defined function


You can get the number of parameters with their name of a function.

PHP provides a class ReflectionFunction. It’s a built-in class, so no
need to add any extra library.

<?php
function get_func_argNames($funcName) {
    $f = new ReflectionFunction($funcName);
    $result = array();
    foreach ($f->getParameters() as $param) {
        $result[] = $param->name;   
    }
    return $result;
}

print_r(get_func_argNames('get_func_argNames'));

?>
Advertisements

2 thoughts on “How to get the number of parameter with their name of a defined function

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s