note 68825 added to function.is-null

From: Date: Sat, 12 Aug 2006 04:18:39 +0000
Subject: note 68825 added to function.is-null
Groups: php.notes 
Request: Send a blank email to php-notes+get-115818@lists.php.net to get a copy of this message
Hello all. The function is really simple, but it seems like others are making it confusing than it should be. is_null() will return true if: the variable has not been set, or the variable has the following values: NULL or null <?php $var = NULL; $var = null; $var; // or if not declared at all ?> without using is_null(), the proper way to check for null values is using === operator. <?php if ($var === NULL) {} // true if ($var === null) {} // true if (is_null($var)) {} // true /* * Any other values for $var will return false */ ?> With that in mind, you can save an extra function call by avoiding is_null() check and just use <?php if ($var === NULL) {} // or if ($var === null) {} ?> When dealing with database nulls (I can't remember whether it's "null" or "NULL"), you're just going to have to write a wrapper function. Here's my untested function: <?php function isnull($data) { /* * I can't remember the string null value the database returns, so I'm making two assumptions */ if ($data === NULL || $data === 'NULL' || $data === 'null') { return true; } return false; } ?> ---- Server IP: 216.194.113.175 Probable Submitter: 67.10.71.245 ---- 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.is-null.php Edit -- https://master.php.net/note/edit/68825 Del: integrated -- https://master.php.net/note/delete/68825/integrated Del: useless -- https://master.php.net/note/delete/68825/useless Del: bad code -- https://master.php.net/note/delete/68825/bad+code Del: spam -- https://master.php.net/note/delete/68825/spam Del: non-english -- https://master.php.net/note/delete/68825/non-english Del: in docs -- https://master.php.net/note/delete/68825/in+docs Del: other reasons-- https://master.php.net/note/delete/68825 Reject -- https://master.php.net/note/reject/68825 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#115818) next »