PHP中ClassName :: class的含义是什么? [英] What does ClassName::class mean in PHP?
本文介绍了PHP中ClassName :: class的含义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我阅读用Laravel框架编写的代码时,我看到了ClassName::class
的许多用法.修饰符::class
是什么意思?这是Laravel或PHP的功能吗?我已经搜索过,但是找不到文档.
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 this a feature of Laravel or PHP? I've searched but been unable to find documentation.
推荐答案
自PHP 5.5起,class关键字也用于类名解析.您可以使用
ClassName::class
获得包含 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.
例如
namespace MyProject;
class Alpha{ }
namespace MyOtherProject;
class Beta{ }
echo Alpha::class; // displays: MyProject\Alpha
echo Beta::class; // displays: MyOtherProject\Beta
这篇关于PHP中ClassName :: class的含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文