note 86919 deleted from function.isset by cmb

From: Date: Sun, 10 Feb 2019 11:25:29 +0000
Subject: note 86919 deleted from function.isset by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-210215@lists.php.net to get a copy of this message
Note Submitter: jwvdveer at gmail dot com ---- 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.

« previous php.notes (#210215) next »