简体   繁体   English

PHP中的反斜杠 - 这是什么意思?

[英]Backslash in PHP — what does it mean?

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). 我刚刚看到在PHP对象的引用中使用了反斜杠,并对此感到好奇(我以前从未见过这个)。 What does it mean? 这是什么意思?

$mail = new SendGrid\Mail();

If you're curious, here's SendGrid's documentation . 如果你很好奇,这里是SendGrid的文档

It's because they're using PHP namespaces . 这是因为他们使用的是PHP命名空间 Namespaces are new as of PHP 5.3. 自PHP 5.3起,命名空间是新的。

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. 它是(imho)他们可能做出的最愚蠢的选择,他们的决定基于一个高度倾斜/偏执的得分系统,只对开发者有意义。

This is syntax for namespaces. 这是名称空间的语法。 You can read more about namespaces at PHP documentation . 您可以在PHP文档中阅读有关命名空间的更多信息。 They they require at least PHP 5.3. 他们至少需要PHP 5.3。

For example: 例如:

namespace SendGrid;
function Mail() {
    // You can access this function by using SendGrid\Mail() externally
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM