note 103603 deleted from function.isset by cmb

From: Date: Sun, 05 Jan 2020 08:11:45 +0000
Subject: note 103603 deleted from function.isset by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-213741@lists.php.net to get a copy of this message
Note Submitter: benallfree at gmail dot com ---- isset() returns TRUE if a value is NULL. That seems wrong to me as there is no way to distinguish between a value set to NULL and a truly undefined value. If you have this problem inside a class, there is a fix: <?php class T { function __isset($att) { $props = get_object_vars($this); return array_key_exists($att, $props); } } $x = new T(); $x->foo_exists = 4; var_dump(isset($x->foo_exists)); // TRUE var_dump(isset($x->bar_exists)); // FALSE ?> [EDITOR thiago NOTE: This snippet has improvements by "Paul Lashbrook"]

« previous php.notes (#213741) next »