Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > media > main > by-pkgid > 0afeee9cca140e167a996902b9a677c5 > files > 2981

php-manual-en-4.3.0-2mdk.noarch.rpm

<HTML
><HEAD
><TITLE
>The magic functions __sleep and __wakeup</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="PHP Manual"
HREF="index.html"><LINK
REL="UP"
TITLE="Classes and Objects"
HREF="language.oop.html"><LINK
REL="PREVIOUS"
TITLE="Serializing objects - objects in sessions"
HREF="language.oop.serialization.html"><LINK
REL="NEXT"
TITLE="References inside the constructor"
HREF="language.oop.newref.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=ISO-8859-1"></HEAD
><BODY
CLASS="sect1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>PHP Manual</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="language.oop.serialization.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 14. Classes and Objects</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="language.oop.newref.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="sect1"
><H1
CLASS="sect1"
><A
NAME="language.oop.magic-functions"
></A
>The magic functions <TT
CLASS="literal"
>__sleep</TT
> and <TT
CLASS="literal"
>__wakeup</TT
></H1
><P
>&#13;   <A
HREF="function.serialize.html"
><B
CLASS="function"
>serialize()</B
></A
> checks if your class has a function with
   the magic name <TT
CLASS="literal"
>__sleep</TT
>. If so, that function is
   being run prior to any serialization. It can clean up the object
   and is supposed to return an array with the names of all variables
   of that object that should be serialized.
  </P
><P
>&#13;   The intended use of <TT
CLASS="literal"
>__sleep</TT
> is to close any
   database connections that object may have, committing pending
   data or perform similar cleanup tasks. Also, the function is
   useful if you have very large objects which need not be
   saved completely.
  </P
><P
>&#13;   Conversely, <A
HREF="function.unserialize.html"
><B
CLASS="function"
>unserialize()</B
></A
> checks for the
   presence of a function with the magic name 
   <TT
CLASS="literal"
>__wakeup</TT
>. If present, this function can
   reconstruct any resources that object may have.
  </P
><P
>&#13;    The intended use of <TT
CLASS="literal"
>__wakeup</TT
> is to
    reestablish any database connections that may have been lost
    during serialization and perform other reinitialization
    tasks.
  </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="language.oop.serialization.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="language.oop.newref.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Serializing objects - objects in sessions</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="language.oop.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>References inside the constructor</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>