如何获取类中的静态变量列表?
对于像...这样的类
class MyClass {
static var1 = "a";
static var2 = "b";
}
,我想在运行时检索静态成员及其值;类似于
Array(
"var1" => "a",
"var2" => "b"
)
PHP 有什么方法可以做到这一点吗?
With a class like
class MyClass {
static var1 = "a";
static var2 = "b";
}
... I'd like to retrieve the static members and their values at runtime; something like
Array(
"var1" => "a",
"var2" => "b"
)
Is there any way to do this in PHP?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
ReflectionClass::getStaticProperties()
来执行此操作:You can use
ReflectionClass::getStaticProperties()
to do this:http://www.php.net/manual/en/reflectionclass.getstaticproperties.php - 尝试
获取有关类和类属性的信息(例如所有静态方法)称为“反射”。
http://www.php.net/manual/en/reflectionclass.getstaticproperties.php - try this
getting information about classes and class properties such as all static methods is called "reflection".