2008-11-28 21:54:24 +00:00
<?xml version="1.0" encoding="utf-8"?>
2009-07-11 06:17:58 +00:00
<!-- $Revision$ -->
2008-11-28 21:54:24 +00:00
<phpdoc:classref xml:id= "class.serializable" xmlns:phpdoc= "http://php.net/ns/phpdoc" xmlns= "http://docbook.org/ns/docbook" xmlns:xlink= "http://www.w3.org/1999/xlink" xmlns:xi= "http://www.w3.org/2001/XInclude" >
2008-11-28 21:56:05 +00:00
<title > The Serializable interface</title>
2008-11-28 21:54:24 +00:00
<titleabbrev > Serializable</titleabbrev>
<partintro >
<!-- {{{ Serializable intro -->
<section xml:id= "serializable.intro" >
&reftitle.intro;
<para >
Interface for customized serializing.
</para>
<para >
Classes that implement this interface no longer support
2012-01-12 15:01:15 +00:00
<link linkend= "object.sleep" > __sleep()</link> and
<link linkend= "object.wakeup" > __wakeup()</link> . The method serialize is
2008-11-28 21:54:24 +00:00
called whenever an instance needs to be serialized. This does not invoke __destruct()
2017-02-17 18:06:35 +00:00
or have any other side effect unless programmed inside the method. When the data is
2008-11-28 21:54:24 +00:00
unserialized the class is known and the appropriate unserialize() method is called as
a constructor instead of calling __construct(). If you need to execute the standard
2009-02-09 12:36:00 +00:00
constructor you may do so in the method.
2008-11-28 21:54:24 +00:00
</para>
2021-11-27 19:30:12 +00:00
<warning >
<para >
As of PHP 8.1.0, a class which implements <interfacename > Serializable</interfacename> without also implementing <link linkend= "object.serialize" > __serialize()</link> and <link linkend= "object.unserialize" > __unserialize()</link> will generate a deprecation warning.
</para>
</warning>
2008-11-28 21:54:24 +00:00
</section>
<!-- }}} -->
<section xml:id= "serializable.synopsis" >
2009-04-24 10:33:28 +00:00
&reftitle.interfacesynopsis;
2008-11-28 21:54:24 +00:00
<!-- {{{ Synopsis -->
<classsynopsis >
2021-12-23 13:25:27 +00:00
<ooclass >
<classname > Serializable</classname>
</ooclass>
2008-11-28 21:54:24 +00:00
<classsynopsisinfo >
2021-07-30 15:01:16 +00:00
<oointerface >
<interfacename > Serializable</interfacename>
</oointerface>
2008-11-28 21:54:24 +00:00
</classsynopsisinfo>
2021-12-23 13:25:27 +00:00
2009-12-29 09:42:00 +00:00
<classsynopsisinfo role= "comment" > &Methods; </classsynopsisinfo>
2021-12-23 13:25:27 +00:00
<xi:include xpointer= "xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.serializable')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[not(@role='procedural')])" >
<xi:fallback />
</xi:include>
2008-11-28 21:54:24 +00:00
</classsynopsis>
<!-- }}} -->
</section>
<section xml:id= "serializable.examples" >
<example xml:id= "serializable.example.basic" > <!-- {{{ -->
<title > Basic usage</title>
<programlisting role= "php" >
< ![CDATA[
< ?php
class obj implements Serializable {
private $data;
public function __construct() {
$this->data = "My private data";
}
public function serialize() {
return serialize($this->data);
}
public function unserialize($data) {
$this->data = unserialize($data);
}
public function getData() {
return $this->data;
}
}
$obj = new obj;
$ser = serialize($obj);
2011-05-11 11:24:59 +00:00
var_dump($ser);
2008-11-28 21:54:24 +00:00
$newobj = unserialize($ser);
var_dump($newobj->getData());
?>
]]>
</programlisting>
&example.outputs.similar;
<screen >
< ![CDATA[
2011-05-11 11:24:59 +00:00
string(38) "C:3:"obj":23:{s:15:"My private data";}"
2008-11-28 21:54:24 +00:00
string(15) "My private data"
]]>
</screen>
</example> <!-- }}} -->
</section>
</partintro>
&language.predefined.serializable.serialize;
&language.predefined.serializable.unserialize;
</phpdoc:classref>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
2009-09-25 07:04:39 +00:00
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
2008-11-28 21:54:24 +00:00
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->