我正在尝试通过调用类读取受保护的变量。我受保护的 $test 和新的 ReflectionClass 的问题在哪里?
<?PHP
class foo
{
protected $test = ['foo' => 'foo'];
public function __construct()
{
$class = get_called_class();
do
{
foreach((new \ReflectionClass($class))->getDefaultProperties() as $property => $value)
var_dump([$class.'::'.$property => $value]);
}
while($class = get_parent_class($class));
}
}
class baz extends foo
{
protected $test = ['baz' => 'baz'];
}
new baz;
实际的:
["baz::test"]=>
["baz"]=> "baz"
["foo::test"]=>
["baz"]=> "baz"
预期的:
["baz::test"]=>
["baz"]=> "baz"
["foo::test"]=>
["foo"]=> "foo"
亲切的问候。