是否有内置的静态方法或属性来引用PHP类,以便它在上下文中表示为字符串?例如:
而不是这个:
$obj->tempFn('MyClass') //MyClass being the name of the class
Run Code Online (Sandbox Code Playgroud)
我想做这个:
$obj->tempFn(MyClass) //Directly references the class name, instead of a string representation
Run Code Online (Sandbox Code Playgroud)
不.但您可以在类中定义一个包含类名的常量,例如:
class foo{
const
NAME = 'foo';
}
Run Code Online (Sandbox Code Playgroud)
并访问它foo::NAME.
在PHP 5.5中,您将能够使用:
foo::class
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3906 次 |
| 最近记录: |