note 86919 added to function.isset

From: Date: Mon, 10 Nov 2008 18:29:29 +0000
Subject: note 86919 added to function.isset
Groups: php.notes 
Request: Send a blank email to php-notes+get-146361@lists.php.net to get a copy of this message
Here a short note on the function tomek wrote: Don't use it, because it is still better to use !$var than !is($var). Some comments on the body of the function: <?php function is($var) { if (!isset($var)) return false; # Variable is always set... Otherwise PHP would have thrown an error on call. if ($var!==false) return true; # So, 0, NULL, and some other values may not behave like isNot? And what about the difference between a class and NULL? return false; } ?> The reason why you shall not use this function: Notice: Undefined variable: {variablename} in {file} on line {__LINE__} It's me as plain as the nose on your face that the piece of code hasn't been tested with E_NOTICE. So my advice in this case is: don't use the above function, but simply use !, and functions such like is_null in the situation they are made for. ---- Server IP: 213.249.64.162 Probable Submitter: 84.81.161.35 ---- Manual Page -- http://www.php.net/manual/en/function.isset.php Edit -- https://master.php.net/note/edit/86919 Del: integrated -- https://master.php.net/note/delete/86919/integrated Del: useless -- https://master.php.net/note/delete/86919/useless Del: bad code -- https://master.php.net/note/delete/86919/bad+code Del: spam -- https://master.php.net/note/delete/86919/spam Del: non-english -- https://master.php.net/note/delete/86919/non-english Del: in docs -- https://master.php.net/note/delete/86919/in+docs Del: other reasons-- https://master.php.net/note/delete/86919 Reject -- https://master.php.net/note/reject/86919 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#146361) next »