declared properties cannot be unset
any set property does exist, even being set to null, regardless how it was set
<?php
class demo_property_exists {
public $my_public;
protected $my_protected;
private $my_private;
function __construct() {
$this->dumper('before-constructed');
$this->my_constructed_int = 123;
$this->my_constructed_null = null;
$this->dumper('after-constructed');
}
public function dumper($name) {
printf("\n[%s] dump:\n", $name);
foreach ($this->my_checklist() as $prop) {
printf("[%s]:\t", $prop);
var_dump(property_exists($this, $prop));
}
}
public function unset_all() {
foreach ($this->my_checklist() as $prop) {
unset($this->$prop);
}
}
private function my_checklist() {
return array('my_public', 'my_protected', 'my_private', 'my_constructed_int', 'my_constructed_null', 'my_assigned_int', 'my_assigned_null',);
}
}
$object = new demo_property_exists();
$object->dumper('before-assigned');
$object->my_assigned_int = 456;
$object->my_assigned_null = null;
$object->dumper('after-assigned');
$object->unset_all();
$object->dumper('after-unset');