declared properties cannot be unset
any set property does exist, even being set to null, regardless how it was set
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 functiondumper($name) {printf("\n[%s] dump:\n",$name);
foreach ($this->my_checklist() as$prop) {printf("[%s]:\t",$prop);var_dump(property_exists($this,$prop));
}
}
public functionunset_all() {
foreach ($this->my_checklist() as$prop) {
unset($this->$prop);
}
}
private functionmy_checklist() {
return array('my_public','my_protected','my_private','my_constructed_int','my_constructed_null','my_assigned_int','my_assigned_null',);
}
}$object= newdemo_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');/*
results:
[before-constructed] dump:
[my_public]: bool(true)
[my_protected]: bool(true)
[my_private]: bool(true)
[my_constructed_int]: bool(false)
[my_constructed_null]: bool(false)
[my_assigned_int]: bool(false)
[my_assigned_null]: bool(false)
[after-constructed] dump:
[my_public]: bool(true)
[my_protected]: bool(true)
[my_private]: bool(true)
[my_constructed_int]: bool(true)
[my_constructed_null]: bool(true)
[my_assigned_int]: bool(false)
[my_assigned_null]: bool(false)
[before-assigned] dump:
[my_public]: bool(true)
[my_protected]: bool(true)
[my_private]: bool(true)
[my_constructed_int]: bool(true)
[my_constructed_null]: bool(true)
[my_assigned_int]: bool(false)
[my_assigned_null]: bool(false)
[after-assigned] dump:
[my_public]: bool(true)
[my_protected]: bool(true)
[my_private]: bool(true)
[my_constructed_int]: bool(true)
[my_constructed_null]: bool(true)
[my_assigned_int]: bool(true)
[my_assigned_null]: bool(true)
[after-unset] dump:
[my_public]: bool(true)
[my_protected]: bool(true)
[my_private]: bool(true)
[my_constructed_int]: bool(false)
[my_constructed_null]: bool(false)
[my_assigned_int]: bool(false)
[my_assigned_null]: bool(false)
*/