note 81228 deleted from function.date-create by googleguy

From: Date: Tue, 22 Oct 2013 08:01:24 +0000
Subject: note 81228 deleted from function.date-create by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-196733@lists.php.net to get a copy of this message
Note Submitter: prikkeldraad at gmail dot com ---- Serialization and unserialization fail for the DateTime object (PHP 5.2.5). With your own __sleep and __wakeup function in a child class you can work around this problem. <?php class MyDateTime extends DateTime { private $_str; public function __sleep(){ $this->_str = $this->format('c'); return array('_str'); } public function __wakeup() { $this->__construct($this->_str); } } ?> Regards, Mick [Ed. Please be aware that this is *not* 100% correct as you lose the timezone information. Always use the standard serialization if it's available!]

« previous php.notes (#196733) next »