note 58356 added to function.serialize
| From: | stephen dot adamson at smius dot com | Date: | Tue, 01 Nov 2005 17:40:11 +0000 |
| Subject: | note 58356 added to function.serialize | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-97937@lists.php.net to get a copy of this message | ||
If you are serializing an object to store it in the database, using __sleep() can save you some
space. The following code will not store empty (null) variables in the serialized string. For my
purposes this saved a lot of space, since some of the member variables would not be given values.
function __sleep()
{
$allVars = get_object_vars($this);
$toReturn = array();
foreach(array_keys($allVars) as $name)
{
if (isset($this->$name))
{
$toReturn[] = $name;
}
}
return $toReturn;
}
----
Manual Page -- http://www.php.net/manual/en/function.serialize.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+58356
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58356&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58356&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58356&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58356&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58356&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58356&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58356&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+58356&report=yes
Search -- http://master.php.net/manage/user-notes.php