note 120214 added to function.property-exists
| From: | Daniel dot Peder at infoset dot com | Date: | Wed, 23 Nov 2016 09:24:09 +0000 |
| Subject: | note 120214 added to function.property-exists | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-207524@lists.php.net to get a copy of this message | ||
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');
/*
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)
*/
----
Server IP: 72.52.91.14
Probable Submitter: 78.102.138.243
----
Manual Page -- http://php.net/manual/en/function.property-exists.php
Edit -- https://master.php.net/note/edit/120214
Del: integrated -- https://master.php.net/note/delete/120214/integrated
Del: useless -- https://master.php.net/note/delete/120214/useless
Del: bad code -- https://master.php.net/note/delete/120214/bad+code
Del: spam -- https://master.php.net/note/delete/120214/spam
Del: non-english -- https://master.php.net/note/delete/120214/non-english
Del: in docs -- https://master.php.net/note/delete/120214/in+docs
Del: other reasons-- https://master.php.net/note/delete/120214
Reject -- https://master.php.net/note/reject/120214
Search -- https://master.php.net/manage/user-notes.php