PHP Doku:: The __wakeup handler - datetime.wakeup.html

Verlauf / Chronik / History: (4) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzDatums- und zeitrelevante ErweiterungenDatum und UhrzeitThe DateTime classDateTime::__wakeup

Ein Service von Reinhard Neidl - Webprogrammierung.

The DateTime class

<<DateTime::sub

The DateTimeZone class>>

DateTime::__wakeup

(PHP 5 >= 5.2.0)

DateTime::__wakeupThe __wakeup handler

Beschreibung

public DateTime DateTime::__wakeup ( void )

The __wakeup handler.

Parameter-Liste

Diese Funktion hat keine Parameter.

Rückgabewerte

Initializes a DateTime object.


2 BenutzerBeiträge:
- Beiträge aktualisieren...
prikkeldraad at gmail dot com
19.06.2009 17:14
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
7.04.2009 17:32
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.



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)