What does a \
do in PHP?
PHP中\做什么?
For example, CSRF4PHP has \FALSE
, \session_id
, and \Exception
:
例如,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);
}
}
3 个解决方案
#1
140
\
(backslash) is the namespace separator in PHP 5.3.
\(反斜杠)是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.
将它放在那里将确保调用来自全局名称空间的函数,即使在当前名称空间中有相同名称的函数。
#2
10
To clarify potential confusion:
阐明潜在的混乱:
The backslash does not imply class inheritance.
反斜杠并不意味着类继承。
In the following, Animal
, Dog
, Shepherd
don't have to be classes, but simply namespaces. Meaning something used to group names together to avoid naming collisions.
在下面的例子中,Animal, Dog, Shepherd并不一定是类,只是名称空间。意思是用来将名称分组在一起以避免命名冲突的东西。
$myDog = new \Animal\Dog\Shepherd\GermanShepherd();
The leading \
means Animal
was declared in the global scope.
领头的动物是在全球范围内宣布的。
#3
6
The \
is used in PHP 5.3 for namespaces. See http://www.php.net/manual/en/language.namespaces.rationale.php for more information on namespaces and PHP.
PHP 5.3中使用的\用于命名空间。有关名称空间和PHP的更多信息,请参见http://www.php.net/manual/en/language.namespaces.rationale.php。
#1
140
\
(backslash) is the namespace separator in PHP 5.3.
\(反斜杠)是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.
将它放在那里将确保调用来自全局名称空间的函数,即使在当前名称空间中有相同名称的函数。
#2
10
To clarify potential confusion:
阐明潜在的混乱:
The backslash does not imply class inheritance.
反斜杠并不意味着类继承。
In the following, Animal
, Dog
, Shepherd
don't have to be classes, but simply namespaces. Meaning something used to group names together to avoid naming collisions.
在下面的例子中,Animal, Dog, Shepherd并不一定是类,只是名称空间。意思是用来将名称分组在一起以避免命名冲突的东西。
$myDog = new \Animal\Dog\Shepherd\GermanShepherd();
The leading \
means Animal
was declared in the global scope.
领头的动物是在全球范围内宣布的。
#3
6
The \
is used in PHP 5.3 for namespaces. See http://www.php.net/manual/en/language.namespaces.rationale.php for more information on namespaces and PHP.
PHP 5.3中使用的\用于命名空间。有关名称空间和PHP的更多信息,请参见http://www.php.net/manual/en/language.namespaces.rationale.php。