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.
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.
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.
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.
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.
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 the Scala programming language? - Quora What do double colons (::) mean in the Scala programming language? :: doesn’t mean anything in general.
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).
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.
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.
::
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With