获取实例的静态属性 [英] Get a static property of an instance

查看:85
本文介绍了获取实例的静态属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在PHP中有一个实例,那么获取该实例的静态属性(类变量")的最简单方法是什么?

If I have an instance in PHP, what's the easiest way to get to a static property ('class variable') of that instance ?

$classvars=get_class_vars(get_class($thing));
$property=$classvars['property'];

声音真的过大了.我希望

Sound really overdone. I would expect

$thing::property

$thing->property

这是一个老问题.有更明显的方法可以在较新的版本中执行此操作 PHP,请在下面搜索.

this is an old question. There are more obvious ways to do this in newer PHP, search below.

推荐答案

您需要先查找类名:

$class = get_class($thing);
$class::$property

$ property当然必须定义为staticpublic.

$property must be defined as static and public of course.

这篇关于获取实例的静态属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆