language.oop.magic-functions.html

来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 51 行

HTML
51
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>The magic functions __sleep and __wakeup</title>  <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="language.oop.serialization.html">Serializing objects - objects in sessions</a></div> <div class="next" style="text-align: right; float: right;"><a href="language.oop.newref.html">References inside the constructor</a></div> <div class="up"><a href="language.oop.html">Classes and Objects (PHP 4)</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="language.oop.magic-functions" class="sect1">  <h2 class="title">The magic functions <i>__sleep</i> and <i>__wakeup</i></h2>  <p class="para">   <a href="function.serialize.html" class="function">serialize()</a> checks if your class has a function with   the magic name <i>__sleep</i>. 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 <b><tt>NULL</tt></b> is serialized and   E_NOTICE is issued.  </p>    <p class="para">   The intended use of <i>__sleep</i> 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, <a href="function.unserialize.html" class="function">unserialize()</a> checks for the   presence of a function with the magic name    <i>__wakeup</i>. If present, this function can   reconstruct any resources that object may have.  </p>    <p class="para">    The intended use of <i>__wakeup</i> is to    reestablish any database connections that may have been lost    during serialization and perform other reinitialization    tasks.  </p> </div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="language.oop.serialization.html">Serializing objects - objects in sessions</a></div> <div class="next" style="text-align: right; float: right;"><a href="language.oop.newref.html">References inside the constructor</a></div> <div class="up"><a href="language.oop.html">Classes and Objects (PHP 4)</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?