Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do two colons mean in PHP?

I don't know what it's doing when we have this situation:

Foo::Bar 

It looks like a path.

like image 861
ben Avatar asked May 25 '10 09:05

ben


People also ask

What does 2 colons mean?

The double colon ( :: ) may refer to: an analogy symbolism operator, in logic and mathematics. a notation for equality of ratios. a scope resolution operator, in computer programming languages.

What does :: class mean in PHP?

Since PHP 5.5, the class keyword is also used for class name resolution. You can get a string containing the fully qualified name of the ClassName class by using ClassName::class. This is particularly useful with namespaced classes.

What does self :: mean in PHP?

self operator: self operator represents the current class and thus is used to access class variables or static variables because these members belongs to a class rather than the object of that class.

What does :: mean in laravel?

Basically its know as Scope resolution operator (::) Simply it is token which allow access to static, constant and overridden properties of method of a class. Example- in laravel we call model like this.


2 Answers

The :: operator is the scope resolution operator. It is used to access class constants or static properties and methods, either from outside the class:

ClassName::CONSTANT_VALUE ClassName::staticMethod() 

Or within a class method to reference the same or a parent class using self and parent:

self::CONSTANT_VALUE self::staticMethod() parent::CONSTANT_VALUE parent::staticMethod() 
like image 149
Gumbo Avatar answered Sep 23 '22 05:09

Gumbo


That's (generally) for accessing a static method or property in a class. It's called the scope resolution operator, or Paamayim Nekudotayim (which leads to some amazingly confusing error messages!). See http://www.php.net/manual/en/language.oop5.paamayim-nekudotayim.php.

like image 22
Chris Avatar answered Sep 20 '22 05:09

Chris