如果你需要获取子类的受保护/私有变量,忽略父类变量,使用如下方式
<?php
class childClass extends parentClass {
private $login;
private $password;
public function __set($key, $val) {
if ($key == 'password')
$this->$key = md5($val);
else
$this->$key = $val;
}
}
class parentClass {
public $name;
public $email;
function __construct() {
$reflection = new ReflectionClass($this);
$vars = array_keys($reflection->getdefaultProperties());
$reflection = new ReflectionClass(__CLASS__);
$parent_vars = array_keys($reflection->getdefaultProperties());
$my_child_vars = array();
foreach ($vars as $key) {
if (!in_array($key, $parent_vars)) {
$my_child_vars[] = $key;
}
}
print_r($my_child_vars);
}
}
$child_class = new childClass();
?>