PHP 中的反斜杠——这是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10788400/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Backslash in PHP -- what does it mean?
提问by Kyle
I just saw the use of a backslash in a reference to a PHP object and was curious about it (I have never seen this before). What does it mean?
我刚刚看到在对 PHP 对象的引用中使用了反斜杠并对此感到好奇(我以前从未见过这种情况)。这是什么意思?
$mail = new SendGrid\Mail();
If you're curious, here's SendGrid's documentation.
如果您好奇,这里是SendGrid 的文档。
采纳答案by ashurexm
It's because they're using PHP namespaces. Namespaces are new as of PHP 5.3.
这是因为他们使用PHP 命名空间。命名空间从 PHP 5.3 开始是新的。
回答by Marc B
It's PHP's namespace operator: http://php.net/manual/en/language.namespaces.php.
它是 PHP 的命名空间操作符:http://php.net/manual/en/language.namespaces.php。
Don't ask why it's a backslash. It's (imho) the stupidest possible choice they could have made, basing their decisions on a highly slanted/bigoted scoring system that made sense only to the devs.
不要问为什么是反斜杠。这是(恕我直言)他们可能做出的最愚蠢的选择,将他们的决定基于高度倾斜/偏执的评分系统,而这种系统仅对开发人员有意义。
回答by Konrad Borowski
This is syntax for namespaces. You can read more about namespaces at PHP documentation. They they require at least PHP 5.3.
这是命名空间的语法。您可以在PHP 文档 中阅读有关名称空间的更多信息。他们至少需要 PHP 5.3。
For example:
例如:
namespace SendGrid;
function Mail() {
// You can access this function by using SendGrid\Mail() externally
}

