mirror of
https://github.com/php/doc-ja.git
synced 2026-03-23 22:52:11 +01:00
131 lines
3.9 KiB
XML
131 lines
3.9 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: f94d903985119d3ac00f4528551df947f57b667f Maintainer: satoruyoshida Status: ready -->
|
|
<reference xml:id="class.serializable" role="class" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude">
|
|
|
|
<title>Serializable インターフェイス</title>
|
|
<titleabbrev>Serializable</titleabbrev>
|
|
|
|
<partintro>
|
|
|
|
<!-- {{{ Serializable intro -->
|
|
<section xml:id="serializable.intro">
|
|
&reftitle.intro;
|
|
<para>
|
|
独自のシリアライズ用のインターフェイスです。
|
|
</para>
|
|
|
|
<para>
|
|
このインターフェイスを実装したクラスは
|
|
<link linkend="object.sleep">__sleep()</link> や
|
|
<link linkend="object.wakeup">__wakeup()</link> をサポートしなくなります。
|
|
シリアライズが必要な場合には、自動的に serialize メソッドがコールされます。
|
|
このメソッドは __destruct() を実行しません。また、
|
|
メソッド内で明示的に書かない限りは一切の副作用を及ぼしません。
|
|
アンシリアライズされるときにはそのクラスが自動的に検知し、__construct()
|
|
メソッドのかわりに適切な unserialize() メソッドがコールされます。
|
|
標準のコンストラクタを実行させたい場合は、unserialize() メソッドの中でそれをコールします。
|
|
</para>
|
|
|
|
<warning>
|
|
<para>
|
|
PHP 8.1.0 以降は、
|
|
<link linkend="object.serialize">__serialize()</link> と
|
|
<link linkend="object.unserialize">__unserialize()</link>
|
|
がない状態で <interfacename>Serializable</interfacename>
|
|
を実装したクラスに対しては、推奨されない警告が発生します。
|
|
</para>
|
|
</warning>
|
|
</section>
|
|
<!-- }}} -->
|
|
|
|
<section xml:id="serializable.synopsis">
|
|
&reftitle.interfacesynopsis;
|
|
|
|
<!-- {{{ Synopsis -->
|
|
<classsynopsis class="interface">
|
|
<oointerface>
|
|
<interfacename>Serializable</interfacename>
|
|
</oointerface>
|
|
|
|
<classsynopsisinfo role="comment">&Methods;</classsynopsisinfo>
|
|
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.serializable')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[@role='Serializable'])">
|
|
<xi:fallback/>
|
|
</xi:include>
|
|
</classsynopsis>
|
|
<!-- }}} -->
|
|
|
|
</section>
|
|
|
|
<section xml:id="serializable.examples">
|
|
&reftitle.examples;
|
|
<example xml:id="serializable.example.basic"><!-- {{{ -->
|
|
<title>基本的な使用法</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);
|
|
|
|
var_dump($ser);
|
|
|
|
$newobj = unserialize($ser);
|
|
|
|
var_dump($newobj->getData());
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.similar;
|
|
<screen>
|
|
<![CDATA[
|
|
string(38) "C:3:"obj":23:{s:15:"My private data";}"
|
|
string(15) "My private data"
|
|
]]>
|
|
</screen>
|
|
</example><!-- }}} -->
|
|
</section>
|
|
|
|
|
|
</partintro>
|
|
|
|
&language.predefined.serializable.serialize;
|
|
&language.predefined.serializable.unserialize;
|
|
|
|
</reference>
|
|
<!-- 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
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
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
|
|
-->
|