如何获取PHP中内置函数的所有参数(参数)及其各自的值,包括可选参数(如果有)?

How to get all the parameters(arguments) and their respective values including the optional ones, if any, of a built-in function in PHP?

我正在使用 PHP 7.2.10

我正在使用内置的 PHP 函数 htmlspecialchars()

以下是我的代码:

<?php
  $new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
  echo $new;
?>

我想在上面的代码中传递函数 htmlspecialchars() 的所有参数。预期参数列表应包括所有参数,包括不可见参数(即默认参数)及其各自的值 here

谢谢。

简而言之:没有。

ReflectionFunction::getParameters and ReflectionParameter::getDefaultValue should theoretically help here, but they don't work for built-in functions.

var_dump(array_map(function ($p) { return $p->getDefaultValue(); }, 
                   (new ReflectionFunction('htmlspecialchars'))->getParameters()));

所以,没有。阅读手册,查看默认值是什么,并将它们硬编码到您的代码中。或者根本不通过它们,因为那毫无意义。