PHP, Tokenizer, find all function arguments

Help me find all the arguments to the funcname function using the token_get_all () function in the source code. It sounds simple, but there are many special options, such as arrays as parameters or calling static methods as parameters. Maybe there is a simple universal solution?

UPD:

I need function arguments passed when you call this. Get them for external file analysis. For example, there is a php file:

<?php
funcname('foo');
funcname(array('foo'), 'bar');

The analyzer should start as follows:

$source = file_get_contents('source.php');
$tokens = token_get_all($source);
...

As a result, you need to get a list like this:

[0] => array('foo'),
[1] => array(array('foo'), 'bar')
+5
source share
1 answer

Instead of using a tokenizer, use reflection. In this case, use ReflectionFunction:

function funcname ($foo, $bar) {

}

$f = new ReflectionFunction('funcname');
foreach ($f->getParameters() as $p) {
    echo $p->getName(), "\n";
}

foo
bar

(, ReflectionParameter), , , .

+5

All Articles