Alf*_*red 150 php namespaces opcode opcache
\在PHP中做什么?
例如,CSRF4PHP有\FALSE,\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);
}
}
Run Code Online (Sandbox Code Playgroud)
Nel*_*elu 20
澄清潜在的混淆:
反斜杠并不意味着类继承.
在下文中,Animal,Dog,Shepherd不必是类,但简单地命名空间.含义用于将名称组合在一起以避免命名冲突的内容.
$myDog = new \Animal\Dog\Shepherd\GermanShepherd();
Run Code Online (Sandbox Code Playgroud)
领先的\手段Animal在全球范围内宣布.
Web*_*ber 17
命名空间
在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"
Run Code Online (Sandbox Code Playgroud)
小智 9
将\在PHP 5.3用于命名空间.有关命名空间和PHP的更多信息,请参见http://www.php.net/manual/en/language.namespaces.rationale.php.