When I read code written in the Laravel framework, I see a lot of uses of ClassName::class
. What does is the meaning of the modifier ::class
? Is th
Please refer to this
::class
Since PHP 5.5, the class keyword is also used for class name resolution.
It just returns the class name with namespace! 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.
namespace NS {
class ClassName {
}
echo ClassName::class;
}
The above example will output:
NS\ClassName
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.
For example
namespace MyProject;
class Alpha{ }
namespace MyOtherProject;
class Beta{ }
echo Alpha::class; // displays: MyProject\Alpha
echo Beta::class; // displays: MyOtherProject\Beta