我尝试实现 __isset 魔术方法,例如以下代码,
为什么我总是收到未定义的索引错误?谁能告诉我该怎么做?
class c {
public $x = array();
public function __get($name) {
return $this->x[$name]; //undefined index: #1:a / #2:b / #3:d
}
public function __isset($name) {
return isset($this->x[$name]);
}
}
$c = new c;
var_dump(isset($c->a));
var_dump(isset($c->a->b)); #1
var_dump(isset($c->b->c)); #2
var_dump(isset($c->d['e'])); #3
为什么以下代码工作正常?我不明白?
$x = array();
var_dump(isset($x->a->b->c));
var_dump(isset($x['a']['b']['c']));