[英]Get all properties except static ones
I tried: 我试过了:
$rc = new \ReflectionClass($this);
$rc->getProperties(ReflectionProperty::IS_PUBLIC || ReflectionProperty::IS_PRIVATE || ReflectionProperty::IS_PROTECTED)
But all that did was give me the one static
property that the class has. 但是所做的只是给我一个类拥有的
static
属性。 It has 3 private
and one static
. 它有3
private
和1个static
。 I just want to know how to weed out the static
ones. 我只想知道如何清除
static
字段。
Your static
properties are also public
, private
or protected
, so it returns them as well. 您的
static
属性也是public
, private
或protected
,因此它也返回它们。 You need to check each property with isStatic()
: 您需要使用
isStatic()
检查每个属性:
foreach($rc->getProperties() as $prop) {
if(!$prop->isStatic()) { // or $prop->isStatic() === false
$result[] = $prop;
}
}
getProperties()
defaults to all properties. getProperties()
默认为所有属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.