What does double colon in laravel means

送分小仙女□ 提交于 2019-12-06 06:13:45

问题


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.


回答1:


:: Scope Resolution Operator

This is called as scope resolution operator. 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.




回答2:


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.


来源:https://stackoverflow.com/questions/39198357/what-does-double-colon-in-laravel-means

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!