Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the '\' in this PHP library mean?

Tags:

oop

php

class

$mail = new SendGrid\Mail();

I don't understand the meaning of \ in between SendGrid and Mail() above line. can anybody tell me what it is and its logic.

like image 617
Anant Waykar Avatar asked Aug 29 '12 16:08

Anant Waykar


1 Answers

That defines the namespace. So the Mail library is in the SendGrid namespace. This is a feature only available in PHP 5.3+.

Basically a namespace is a way to limit a scope within which you can have class names. It allows you to have classes with the same name in many different name spaces without collisions between the class definitions. It's great for writing libraries because it makes it so your library's end user is not constrained by your naming conventions.

like image 165
hsanders Avatar answered Sep 24 '22 07:09

hsanders