我正在使用一个类,该类具有一个要在运行时取消/销毁的属性。该解封发生在一个特定的方法,但该方法调用它返回TRUE的property_exists,虽然它不能直接访问属性$this->property,因为它返回的通知Notice: Undefined property:...
public function get(int $id) {
if ($record->data) {
$this->_transform($record); // Calling method that unsets prop
}
if (! property_exists($this, 'isEmpty') ) { // FALSE
$this->transform();
}else{
echo $this->isEmpty; // FALSE as well!
}
return $this;
}
正如您在取消设置后的代码中看到的那样,property_exists返回TRUE不应发生,但该属性是未定义的。
编辑
似乎如果该属性是在类的架构中声明的,则它无法被破坏/取消设置(请参阅所选答案的演示),并且实际上它的行为自相矛盾:property_exists => TRUE,object-> property => warning
但是,如果未定义属性而是在对象的构造中创建了该属性,则可以将其取消设置并按预期方式运行。
largeQ