如果我有stdObject发言权,$a。
stdObject
$a
当然,分配新的属性没有问题$a,
$a->new_property = $xyz;
但是之后我想将其删除,因此unset这里无济于事。
unset
所以,
$a->new_property = null;
是这样的。但是,还有一种更“优雅”的方式吗?
unset($a->new_property);
这适用于数组元素,变量和对象属性。
例:
$a = new stdClass(); $a->new_property = 'foo'; var_export($a); // -> stdClass::__set_state(array('new_property' => 'foo')) unset($a->new_property); var_export($a); // -> stdClass::__set_state(array())