Kyle Cureau
Kyle Cureau

Reputation: 19366

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). What does it mean?

$mail = new SendGrid\Mail();

If you're curious, here's SendGrid's documentation.

Upvotes: 43

Views: 41980

Answers (3)

ashurexm
ashurexm

Reputation: 6335

It's because they're using PHP namespaces. Namespaces are new as of PHP 5.3.

Upvotes: 37

null
null

Reputation: 11839

This is syntax for namespaces. You can read more about namespaces at PHP documentation. They they require at least PHP 5.3.

For example:

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

Upvotes: 9

Marc B
Marc B

Reputation: 360572

It's PHP's namespace operator: 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.

Upvotes: 20

Related Questions