我有一个抽象类和一个实现类:
abstract class AbstractClass {
public function __construct() { }
public function get($property) {
$rc = new \ReflectionClass($this);
$p = $rc->getProperty($property);
$p->setAccessible(true);
return $p->getValue($this);
}
public function set($property, $value) {
$rc = new \ReflectionClass($this);
$p = $rc->getProperty($property);
$p->setAccessible(true);
$p->setValue($this, $value);
return $this;
}
}
abstract class MetadataClass extends AbstractClass {
private $metadataA;
private $metadataB;
}
class ActualClass extends MetadataClass {
private $realField1;
private $realField2;
}
我声明并尝试从/向子类获取/设置属性:
$ac = new ActualClass();
$ac->set('metadataA', 'Hello World');
echo $ac->get('metadataA');
我收到了:
ReflectionException 0 Property metadataA does not exist in AbstractClass.php on line 13
这是ReflectionClass
的限制还是我错过了什么?这是still a bug in PHP吗?