note 29976 added to function.is-null
| From: | spdaniel at NOSPAM dot hotmail dot com | Date: | Mon, 03 Mar 2003 04:55:21 +0000 |
| Subject: | note 29976 added to function.is-null | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-44757@lists.php.net to get a copy of this message | ||
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();
--
http://www.php.net/manual/en/function.is-null.php
http://master.php.net/manage/user-notes.php?action=edit+29976
http://master.php.net/manage/user-notes.php?action=delete+29976
http://master.php.net/manage/user-notes.php?action=reject+29976