mirror of
https://github.com/php/doc-pl.git
synced 2026-03-26 08:02:10 +01:00
126 lines
3.7 KiB
XML
126 lines
3.7 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- EN-Revision: f94d903985119d3ac00f4528551df947f57b667f Maintainer: sobak Status: ready -->
|
|
<!-- $Revision$ -->
|
|
<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>Interfejs Serializable</title>
|
|
<titleabbrev>Serializable</titleabbrev>
|
|
|
|
<partintro>
|
|
|
|
<!-- {{{ Serializable intro -->
|
|
<section xml:id="serializable.intro">
|
|
&reftitle.intro;
|
|
<para>
|
|
Interfejs dla własnej serializacji.
|
|
</para>
|
|
|
|
<para>
|
|
Klasy które implementują ten interfejs, nie korzystają już z metod
|
|
<link linkend="object.sleep">__sleep()</link> ani
|
|
<link linkend="object.wakeup">__wakeup()</link>. Gdy instancja musi być
|
|
zserializowana, wywoływana jest metoda serialize. Nie powoduje to wywołania __destruct()
|
|
ani żadnych innych efektów ubocznych, chyba że zaprogramowano to wprost wewnątrz tej metody.
|
|
Gdy dane są deserializowane, znana jest klasa, więc wołana jest odpowiednia metoda unserialize()
|
|
i działa ona jak konstruktor, zamiast metody __construct(). Jeżeli chcesz wywołać standardowy
|
|
konstruktor, możesz to zrobić w tej metodzie.
|
|
</para>
|
|
|
|
<warning>
|
|
<para>
|
|
Począwszy od PHP 8.1.0 klasa które implementuje interfejs <interfacename>Serializable</interfacename>, a nie implementuje metod <link linkend="object.serialize">__serialize()</link> i <link linkend="object.unserialize">__unserialize()</link> spowoduje wygenerowanie komunikatu <constant>E_DEPRECATED</constant>.
|
|
</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>Basic usage</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
class obj implements Serializable {
|
|
private $data;
|
|
public function __construct() {
|
|
$this->data = "Moje prywatne dane";
|
|
}
|
|
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(41) "C:3:"obj":23:{s:18:"Moje prywatne dane";}"
|
|
string(18) "Moje prywatne dane"
|
|
]]>
|
|
</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
|
|
-->
|