note 81228 modified in function.date-create by derick

From: Date: Tue, 13 May 2008 20:20:02 +0000
Subject: note 81228 modified in function.date-create by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-139362@lists.php.net to get a copy of this message
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!] --was-- 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 http://php.net/manual/en/function.date-create.php

« previous php.notes (#139362) next »