note 43664 deleted from function.serialize by aharvey

From: Date: Tue, 06 Nov 2012 02:03:55 +0000
Subject: note 43664 deleted from function.serialize by aharvey
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-191747@lists.php.net to get a copy of this message
Note Submitter: Andrew dot Morrison at stanford dot edu ---- Correction to my last note: __sleep should return an array only containing the names of instance-variables to serialize. A simple (if not a little wasteful) hack to serialize all but a few class vars is to use get_class_vars as follows: <?php class strawman { var $good_var; var $lame_var; function __sleep() { print "Function __sleep() called\n"; $vars = get_class_vars('strawman'); unset($vars['lame_var']); return array_keys($vars); } function __wakeup() { print "Function __wakeup() called\n"; } function strawman() { } } session_start(); if(session_is_registered('strawman')) { print("session data:\n"); print_r($_SESSION['strawman']); session_destroy(); } else { $strawman =& new strawman(); session_register('strawman'); print("new session data:\n"); print_r($_SESSION['strawman']); } ?>

« previous php.notes (#191747) next »