note 69025 added to function.isset

From: Date: Sun, 20 Aug 2006 12:20:57 +0000
Subject: note 69025 added to function.isset
Groups: php.notes 
Request: Send a blank email to php-notes+get-116084@lists.php.net to get a copy of this message
In response to 10-Feb-2006 06:02, isset($v) is in all (except possibly buggy) cases equivalent to !is_null($v). And no, it doesn't actually test if a variable is set or not by my definition "$v is set if unset($v) has no effect". <?php unset($c); //force $c to be unset var_dump($a=&$c); // NULL, but this actually sets $a and $c to the 'same' NULL. var_dump(isset($c)); // bool(false) var_dump($a = 5); // int(5) var_dump($c); // int(5) unset($c); var_dump($a=&$c); // NULL var_dump(isset($c)); // bool(false) unset($c); var_dump($a = 5); // int(5) var_dump($c); // NULL ?> In the following example, we see an alternate method of testing if a variable is actually set or not: <?php var_dump(array_key_exists('c',get_defined_vars())); // false var_dump(isset($c)); // also false var_dump($c); // manipulate $c a bit... var_dump((string)$c); var_dump(print_r($c,true)); var_dump($a=$c); var_dump(array_key_exists('c',get_defined_vars())); // ... still false var_dump($c = NULL); // this sets $c var_dump(array_key_exists('c',get_defined_vars())); // true! var_dump(isset($c)); // false; isset() still says it's unset unset($c); // actually unset it var_dump(array_key_exists('c',get_defined_vars())); // false var_dump($a=&$c); var_dump(array_key_exists('c',get_defined_vars())); // true! unset($c); // unset it again var_dump(&$c); // &NULL var_dump(array_key_exists('c',get_defined_vars())); // true! ?> Obviously, null values take up space (or they wouldn't show up in get_defined_vars). Also, note that &$v sets $v to NULL if it is unset. ---- Server IP: 85.116.0.130 Probable Submitter: 82.71.54.164 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.isset.php Edit -- https://master.php.net/note/edit/69025 Del: integrated -- https://master.php.net/note/delete/69025/integrated Del: useless -- https://master.php.net/note/delete/69025/useless Del: bad code -- https://master.php.net/note/delete/69025/bad+code Del: spam -- https://master.php.net/note/delete/69025/spam Del: non-english -- https://master.php.net/note/delete/69025/non-english Del: in docs -- https://master.php.net/note/delete/69025/in+docs Del: other reasons-- https://master.php.net/note/delete/69025 Reject -- https://master.php.net/note/reject/69025 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#116084) next »