php - 使用下划线 (_) 作为 PHP 函数名

标签 php

根据 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/

相关文章:

php - 3 个表 mySQL 连接,具有来自同一列的 2 个 WHERE 子句 - 只有一个有效

php - 如何保存表单中的信息?

php - 序列化、反序列化、添加元素并再次序列化

javascript - json_encode 是否非常挑剔?

php curl 使用 GET 发送变量发送奇怪的结果

php - db4free.net 错误 : "Connection failed: Server sent charset unknown to the client"

PHP fopen、fwrite 和 fclose 继续没有错误,但没有创建文件

php - MySQL:对 ID 进行分组并在单独的列上显示不同的值

php - Slim framework v3 路由条件

php - 如何选择记录并显示文本以及 COUNT?