(PHP 5 >= 5.2.0)
DateTime::__wakeup -- DateTimeImmutable::__wakeup -- DateTimeInterface::__wakeup — The __wakeup handler
The __wakeup() handler.
此函数没有参数。
Initializes a DateTime object.
prikkeldraad at gmail dot com (2009-06-19 08:14:20)
If you use a version prior to 5.3 you can make __wakeup and __toString work using the following piece of code.
<?php
class ExtendedDateTime extends DateTime {
private $_date_time;
public function __toString() {
return $this->format('c'); // format as ISO 8601
}
public function __sleep() {
$this->_date_time = $this->format('c');
return array('_date_time');
}
public function __wakeup() {
$this->__construct($this->_date_time);
}
}
?>
Hope this helps someone.
TheDO (2009-04-07 08:32:35)
Be aware, even though this __wake() method exists as of PHP 5.2, DateTime objects don't retain their values when unserialized under PHP 5.2. PHP 5.3 fixes this.