谁能解释为什么这会返回错误:
$test = new myclass();
class myclass {
private $object = (object) NULL;
public function addmember() {
$this->object->member1 = 'member 1';
}
}
$test -> addmember();
...这没关系:
$test = new myclass();
class myclass {
private $object = '';
public function addmember() {
$this->object = (object) NULL;// new stdClass();
$this->object->member1 = 'member 1';
}
}
$test -> addmember();
但为什么?谁能解释为什么第一个例子是错误的?为什么我必须在函数中添加“(object)NULL”行?