Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 10077

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>The magic functions __sleep and __wakeup</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="oop4.serialization.html">Serializing objects - objects in sessions</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="oop4.newref.html">References inside the constructor</a></div>
 <div class="up"><a href="oop4.html">Classes and Objects (PHP 4)</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="oop4.magic-functions" class="sect1">
  <h2 class="title">The magic functions <em>__sleep</em> and <em>__wakeup</em></h2>

  <p class="para">
    <span class="function"><a href="function.serialize.html" class="function">serialize()</a></span> checks if your class has a function with
   the magic name <em>__sleep</em>. 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.
   If the method doesn&#039;t return anything then <strong><code>NULL</code></strong> is serialized and
   <strong><code>E_NOTICE</code></strong> is issued.
  </p>
  
  <p class="para">
   The intended use of <em>__sleep</em> is to commit 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 class="para">
   Conversely,  <span class="function"><a href="function.unserialize.html" class="function">unserialize()</a></span> checks for the
   presence of a function with the magic name 
   <em>__wakeup</em>. If present, this function can
   reconstruct any resources that object may have.
  </p>
  
  <p class="para">
    The intended use of <em>__wakeup</em> is to
    reestablish any database connections that may have been lost
    during serialization and perform other reinitialization
    tasks.
  </p>
 </div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="oop4.serialization.html">Serializing objects - objects in sessions</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="oop4.newref.html">References inside the constructor</a></div>
 <div class="up"><a href="oop4.html">Classes and Objects (PHP 4)</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>