Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does double colon in laravel means

Example :

Auth::guard($guard)->guest()

I dont get what double colon (::) notation means in laravel framework. from http://php.net/manual/en/language.oop5.paamayim-nekudotayim.php I learn that it stand for scope resolution operator to access static, constant and overridden properties or methods of a class. but from laravel I learn that Auth means the alias for class facade so I need an explanation of the example above especially guard(parameter)->guest() means.
I'm still new to php and now learning laravel framework for my back-end.

like image 518
Jsnow Avatar asked Aug 29 '16 04:08

Jsnow


People also ask

What does the double colon mean in PHP?

The Scope Resolution Operator (also called Paamayim Nekudotayim) or in simpler terms, the double colon, is a token that allows access to static, constant, and overridden properties or methods of a class. When referencing these items from outside the class definition, use the name of the class.

What does a double colon 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 Laravel?

Using the ::class keyword in Laravel Since PHP 5.5 the class keyword is used for class name resolution. This means it returns the fully qualified ClassName. This is extremely useful when you have namespaces, because the namespace is part of the returned name.

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 is the use of double colon in Java?

Double colon (::) operator in Java. The double colon (::) operator, also known as method reference operator in Java, is used to call a method by referring to it with the help of its class directly. They behave exactly as the lambda expressions.

What do double colons(::) mean in Scala programming language?

What do double colons (::) mean in the Scala programming language? - Quora What do double colons (::) mean in the Scala programming language? :: doesn’t mean anything in general.

What is the use of colon colon method in Scala?

In Scala almost anything can be a name a method and just like foo.bar (i) is calling the method bar on object foo with i as argument, foo.:: (i) is calling the colon colon method on object foo with i as an argument. Usually this is used as infix notation operator (in scala any method can be used as an operator).

What is the use of translation function in Laravel?

This function was released back in laravel 5.4 to support JSON-based translations. If you are developing a multi-language project, defining every string with a short key starts to can make things really confusing. Basically, it’s better to use the default translation of the string as the key.


2 Answers

You are likely encountering this as a way of accessing a static method or property of a class.

For example:

class Foo
{
    public static function bar()
    {
      return "bar";
    }
}

Foo::bar // access the bar method without instantiating the Foo class.
like image 81
Brad Avatar answered Sep 17 '22 06:09

Brad


:: Scope Resolution Operator

:: is called as scope resolution operator (AKA Paamayim Nekudotayim). This operator is used to refer the scope of some block or program context like classes, objects, namespace and etc. For this reference an identifier is used with this operator to access or reproduce the code inside that scope.

Reference

Auth::guard($guard)->guest() : In this line you are using the guard() method of static class Auth. To use the function of a static class we use :: Scope Resolution Operator.

like image 25
Mayank Pandeyz Avatar answered Sep 21 '22 06:09

Mayank Pandeyz