您可以使用 ReflectionFunction 類別列出所有參數。 不需要像 Nguyet.Duc 建議的那樣解析選定的檔案/檔案。
https://php.dev.org.tw/manual/pl/class.reflectionfunction.php
範例
<?php
函數 foo(&$bar, $big, $small = 1) {}
函數 bar($foo) {}
函數 noparams() {}
函數 byrefandopt(&$the = 'one') {}
$functions = get_defined_functions();
$functions_list = array();
foreach ($functions['user'] as $func) {
$f = new ReflectionFunction($func);
$args = array();
foreach ($f->getParameters() as $param) {
$tmparg = '';
if ($param->isPassedByReference()) $tmparg = '&';
if ($param->isOptional()) {
$tmparg = '[' . $tmparg . '$' . $param->getName() . ' = ' . $param->getDefaultValue() . ']';
} else {
$tmparg.= '&' . $param->getName();
}
$args[] = $tmparg;
unset ($tmparg);
}
$functions_list[] = '函數 ' . $func . ' ( ' . implode(', ', $args) . ' )' . PHP_EOL;
}
print_r($functions_list);
?>
輸出
陣列
(
[0] => 函數 foo ( &&bar, &big, [$small = 1] )
[1] => 函數 bar ( &foo )
[2] => 函數 noparams ( )
[3] => 函數 byrefandopt ( [&$the = one] )
)