根据 http://php.net/manual/en/functions.user-defined.php ,我应该可以使用下划线 (_) 作为函数名:
Function names follow the same rules as other labels in PHP. A valid function name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*.
但是,以下命令会终止我的程序而不会导致任何错误:
error_reporting(E_ALL);
echo('start');
function _($x){return ($x)?htmlspecialchars($x):'nbsp;';}
echo('end');
我使用的是 PHP 版本 5.3.18。我不明白什么?
最佳答案
已经有一个名为_
的内置函数;它是 gettext
的别名.
您可能会遇到 Fatal error: Cannot redeclare _()
,但根据您对 display_errors
的设置,该错误可能不会输出到您的屏幕。您还可以查看 log_errors
指令。
关于php - 使用下划线 (_) 作为 PHP 函数名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13723936/