函数名称前面的 \(反斜杠)是什么意思?
\
在 PHP 中起什么作用?
例如, CSRF4PHP 具有 \FALSE< /code>、
\session_id
和 \Exception
:
public function __construct($timeout=300, $acceptGet=\FALSE){
$this->timeout = $timeout;
if (\session_id()) {
$this->acceptGet = (bool) $acceptGet;
} else {
throw new \Exception('Could not find session id', 1);
}
}
What does a \
do in PHP?
For example, CSRF4PHP has \FALSE
, \session_id
, and \Exception
:
public function __construct($timeout=300, $acceptGet=\FALSE){
$this->timeout = $timeout;
if (\session_id()) {
$this->acceptGet = (bool) $acceptGet;
} else {
throw new \Exception('Could not find session id', 1);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(5)
赠意2024-10-20 12:01:01
命名空间
在 PHP 5.3+ 中,反斜杠 \
符号用于命名空间。它是指示命名空间的起始符号,也用作子命名空间名称之间的分隔符。
请参阅官方文档了解
命名空间。
Opcache
此外,在 PHP 7.0+ 中,一些函数被 OPCache 替换为操作码,这使得这些特定函数的运行速度更快。但是,这仅当函数放置在根命名空间中时才有效。请参阅有关此主题的讨论。所以除了命名空间之外,\
也会间接影响代码优化。
以下本机函数受益于此效果:
"array_slice"
"assert"
"boolval"
"call_user_func"
"call_user_func_array"
"chr"
"count"
"defined"
"doubleval"
"floatval"
"func_get_args"
"func_num_args"
"get_called_class"
"get_class"
"gettype"
"in_array"
"intval"
"is_array"
"is_bool"
"is_double"
"is_float"
"is_int"
"is_integer"
"is_long"
"is_null"
"is_object"
"is_real"
"is_resource"
"is_string"
"ord"
"strlen"
"strval"
"function_exists"
"is_callable"
"extension_loaded"
"dirname"
"constant"
"define"
拥抱没勇气2024-10-20 12:01:01
\
在 PHP 5.3 中用于命名空间。请参阅 http://www.php.net/manual/en/language。 namespaces.rationale.php 了解有关命名空间和 PHP 的更多信息。
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
\
(反斜杠)是 PHP 5.3 中的命名空间分隔符。函数开头之前的
\
表示 全局命名空间。将其放在那里将确保调用的函数来自全局命名空间,即使当前命名空间中存在同名函数。
\
(backslash) is the namespace separator in PHP 5.3.A
\
before the beginning of a function represents the Global Namespace.Putting it there will ensure that the function called is from the global namespace, even if there is a function by the same name in the current namespace.