tags:

views:

35

answers:

2

In PHP, I have created a user defined function. Example:

<?php
function test($one, $two) {
    // do things
}
?>

I would like to find the names of the function parameters. How would I go about doing this?

This is an example of what I would like:

<?php
function test($one, $two) {
    // do things
}

$params = magic_parameter_finding_function('test');
print_r($params);
?>

This would output:

Array
(
    [0] => one
    [1] => two
)

Also this is very important that I am able to get the user defined function parameter names outside the scope of the function. Thanks in advance!

+4  A: 

You can do this using reflection...

$reflector = new ReflectionFunction('test');
$params = array();
foreach ($reflector->getParameters() as $param) {
    $params[] = $param->name;
}
print_r($params);
ircmaxell
Might need to be $params[] = $param->name ? Otherwise I think overall reflection is the right idea.
Beau Simensen
@Beau Simensen, yes good call. I forgot that bit (I've edited it back in)...
ircmaxell
A: 

you can use count_parameter a php built in function