note 29976 deleted from function.is-null by nlopess

From: Date: Tue, 03 Feb 2004 14:55:03 +0000
Subject: note 29976 deleted from function.is-null by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-64596@lists.php.net to get a copy of this message
Note Submitter: spdaniel@NOSPAM.hotmail.com ---- If you unserialize NULL, you do not have a NULL value, and is_null() will be false. Here is an example: one.php: { ... if (condition){ $_SESSION['value']= null; } else { $_SESSION['value'] = serialize(new SomeObject()); } ... } two.php: { ... $variable = unserialize($_SESSION['value']); if (is_null($variable)){ echo 'NULL'; } else { echo 'Not Null'; } ... } (Assume that two.php is called sometime after one.php) it doesn't matter if condition is true or false, you will always get 'Not Null' from two.php. If you take out the unserialize(), the is_null() test will work as expected, but then the object will not be accessable properly if that was what was stored in the session. One possible workaround is to use is_object() instead of is_null();

« previous php.notes (#64596) next »