mirror of
https://github.com/macintoshplus/doc-fr.git
synced 2026-03-24 08:52:09 +01:00
131 lines
3.7 KiB
XML
131 lines
3.7 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- EN-Revision: f94d903985119d3ac00f4528551df947f57b667f Maintainer: yannick Status: ready -->
|
|
<!-- Reviewed: yes -->
|
|
<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>L'interface Serializable</title>
|
|
<titleabbrev>Serializable</titleabbrev>
|
|
|
|
<partintro>
|
|
|
|
<!-- {{{ Serializable intro -->
|
|
<section xml:id="serializable.intro">
|
|
&reftitle.intro;
|
|
<para>
|
|
Interface permettant de personnaliser la sérialisation.
|
|
</para>
|
|
|
|
<para>
|
|
Les classes implémentant cette interface ne supportent plus
|
|
<link linkend="object.sleep">__sleep()</link> et
|
|
<link linkend="object.wakeup">__wakeup()</link>.
|
|
La méthode de sérialisation est appelée chaque fois qu'une
|
|
instance doit être sérialisée. Elle n'appelle pas la méthode
|
|
__destruct() et n'a aucun effet sur le contenu de cette méthode.
|
|
Lorsque les données sont sérialisées, la classe est connue et
|
|
la méthode unserialize() appropriée est appelée comme constructeur
|
|
au lieu d'appeler __construct(). Si vous devez appeler le constructeur
|
|
standard, vous pouvez le faire dans la méthode.
|
|
</para>
|
|
|
|
<warning>
|
|
<para>
|
|
À partir de PHP 8.1.0, une classe qui implémente <interfacename>Serializable</interfacename>
|
|
sans aussi implémenter <link linkend="object.serialize">__serialize()</link>
|
|
et <link linkend="object.unserialize">__unserialize()</link> génèrera
|
|
une notice de dépréciation.
|
|
</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>Exemple simple</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
class obj implements Serializable {
|
|
private $data;
|
|
public function __construct() {
|
|
$this->data = "Mes données privées";
|
|
}
|
|
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:19:"Mes données privées";}"
|
|
string(19) "Mes données privées"
|
|
]]>
|
|
</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
|
|
-->
|