略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: DateTime::__wakeup

2024-11-13

DateTime::__wakeup

DateTimeImmutable::__wakeup

DateTimeInterface::__wakeup

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

DateTime::__wakeup -- DateTimeImmutable::__wakeup -- DateTimeInterface::__wakeupThe __wakeup handler

说明

public DateTime::__wakeup(): void
public DateTimeImmutable::__wakeup(): void
public DateTimeInterface::__wakeup(): void

The __wakeup() handler.

参数

此函数没有参数。

返回值

Initializes a DateTime object.

add a noteadd a note

User Contributed Notes 1 note

up
11
prikkeldraad at gmail dot com
13 years ago
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.

官方地址:https://www.php.net/manual/en/datetime.wakeup.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3