note 59782 deleted from function.is-null by bjori

From: Date: Wed, 03 May 2006 13:04:49 +0000
Subject: note 59782 deleted from function.is-null by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-110450@lists.php.net to get a copy of this message
Note Submitter: jsjacobs at piercedmedia dot com ---- I have variables that may be set to empty ($test = "";) when passed into a fuction and as such may be set, but not null, but still empty. I wanted to know the difference between these so I created a test displaying all errors. (I hate even seeing notices). first I check isset, is_null, and empty on an unset variable, then set the variable empty ($test = "";) <?php error_reporting(2047); if(is_null($test)) { print 'This is Null<BR>'; } else { print 'Not Null<BR>'; } if(isset($test)) { print 'This is Set<BR>'; } else { print 'This is Not Set<BR>'; } if(empty($test)) { print 'This is Empty<BR>'; } else { print 'This is Not Empty<BR>'; } $test = ''; if(is_null($test)) { print 'This is Null<BR>'; } else { print 'This is Not Null<BR>'; } if(isset($test)) { print 'This is Set<BR>'; } else { print 'This is Not Set<BR>'; } if(empty($test)) { print 'This is Empty<BR>'; } else { print 'This is Not Empty<BR>'; } ?> And the results ---------------------------------------------- Notice: Undefined variable: test in /var/www/htdocs/test.php on line 4 This is Null This is Not Set This is Empty This is Not Null This is Set This is Empty We can conclude that is_null will error on an unset variable, and thus is not the same as isset.

« previous php.notes (#110450) next »