问题描述
假设您有一个带有私有属性 $a 的类 A,以及一个继承自它的类 B.如果我在 B 的实例上使用 ReflectionClass::getProperty,我会收到一个致命错误,即该属性不存在.这是有道理的,因为它是一种私有方法.然而, ReflectionClass::hasProperty 仍然返回 true.这是一个错误吗?
Suppose you have a class A with a private property $a, and a class B which inherits from that.If I use ReflectionClass::getProperty on an instance of B, I get a fatal error, that the property doesn't exists. This makes sense, as it is it a private method. However, ReflectionClass::hasProperty returns true, nonetheless. Is this a bug?
推荐答案
这个 bug 好像是关于这个问题的:错误 #47808:hasProperty 与 getProperty 和新的 ReflectionProperty 不一致
This bug seems to be about this problem : Bug #47808 : hasProperty inconsistent with getProperty and new ReflectionProperty
它已于 8 月 4 日标记为已在 SVN 中修复",这是最近的一次;也许它是在比您使用的版本更新的 PHP 版本中解决的?
It's been marked as "fixed in SVN" on August the 4th, which is quite recent ; maybe it's solved in a version of PHP more recent than the one you are using ?
好吧,似乎没有出现在 PHP 5 ChangeLog --所以我猜这个修复程序还没有发布......或者没有记录或任何东西......
Well, doesn't seem to appear in the PHP 5 ChangeLog -- so I'm guessing that fix has not been released yet... Or not documented or anything...
这篇关于ReflectionClass::getProperty 用于继承类中的私有属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!