这是一个复杂的问题。即使在您的示例中,函数的第二个参数也没有名称,因为它是调用另一个函数的返回值。
您可能会幸运地使用token_get_all()为您标记代码,然后您可以遍历结果并尝试获得所需的内容。
$tokens = token_get_all('<?php my_function($var1, some_other_function($othervar1, $othervar2)); ?>');
print_r($tokens);
产量:
Array
(
[0] => Array
(
[0] => 372
[1] => <?php
[2] => 1
)
[1] => Array
(
[0] => 307
[1] => my_function
[2] => 1
)
[2] => (
[3] => Array
(
[0] => 309
[1] => $var1
[2] => 1
)
[4] => ,
[5] => Array
(
[0] => 375
[1] =>
[2] => 1
)
[6] => Array
(
[0] => 307
[1] => some_other_function
[2] => 1
)
[7] => (
[8] => Array
(
[0] => 309
[1] => $othervar1
[2] => 1
)
[9] => ,
[10] => Array
(
[0] => 375
[1] =>
[2] => 1
)
[11] => Array
(
[0] => 309
[1] => $othervar2
[2] => 1
)
[12] => )
[13] => )
[14] => ;
[15] => Array
(
[0] => 375
[1] =>
[2] => 1
)
[16] => Array
(
[0] => 374
[1] => ?>
[2] => 1
)
)
使用解析器标记列表,您可以遍历该数组并找出传递给函数的参数是什么。即便如此,它也可能过于笼统,因为您的调用my_function
只是T_STRING
Zend 引擎最终在函数表中查找并调用该函数(如果它存在),或者如果它不存在则抛出一个致命错误的一个标记。