下面的代码使这更容易解释:
<?php
class a
{
public $dog = 'woof';
public $cat = 'miaow';
private $zebra = '??';
}
class b extends a
{
protected $snake = 'hiss';
public $owl = 'hoot';
public $bird = 'tweet';
}
$test = new b();
print_r(get_object_vars($test));
目前这返回:
Array
(
[owl] => hoot
[bird] => tweet
[dog] => woof
[cat] => miaow
)
我该怎么做才能找到只在 b 类中定义或设置的属性(例如,只有猫头鹰和鸟)?