__set_state magic method (bug #33203)

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@199894 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Jakub Vrana 2005-11-03 10:45:48 +00:00
parent a7a0ce13e3
commit e3e1b80869
2 changed files with 66 additions and 4 deletions

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.11 $ -->
<!-- $Revision: 1.12 $ -->
<sect1 id="language.oop5.magic">
<title>Magic Methods</title>
<para>
@ -16,6 +16,7 @@
<literal>__sleep</literal>,
<literal>__wakeup</literal>,
<literal>__toString</literal>,
<literal>__set_state</literal>,
<link linkend="language.oop5.cloning">__clone</link> and
<link linkend="language.oop5.autoload">__autoload</link>
are magical in PHP classes. You
@ -166,6 +167,18 @@ echo "text $class";
</programlisting>
</example>
</sect2>
<sect2 id="language.oop5.magic.set-state">
<title><literal>__set_state</literal></title>
<para>
This <link linkend="language.oop5.static">static</link> method is called
for classes exported by <function>var_export</function> since PHP 5.1.0.
</para>
<para>
The only parameter of this method is an array containing exported
properties in the form <literal>array('property' => value, ...)</literal>.
</para>
</sect2>
</sect1>
<!-- Keep this comment at the end of the file

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.10 $ -->
<!-- $Revision: 1.11 $ -->
<!-- splitted from ./en/functions/var.xml, last change in rev 1.6 -->
<refentry id="function.var-export">
<refnamediv>
@ -55,6 +55,32 @@
</para>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>5.1.0</entry>
<entry>
Possibility to export classes and arrays containing classes using the
<link linkend="language.oop5.magic.set-state">__set_state</link> magic
method.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
@ -98,6 +124,29 @@ echo $v;
<screen>
<![CDATA[
3.1
]]>
</screen>
</example>
</para>
<para>
<example>
<title>Exporting classes since PHP 5.1.0</title>
<programlisting role="php">
<![CDATA[
<?php
class A { public $var; }
$a = new A;
$a->var = 5;
var_export($a);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
A::__set_state(array(
'var' => 5,
))
]]>
</screen>
</example>
@ -108,8 +157,8 @@ echo $v;
&reftitle.notes;
<note>
<para>
Variables of type <type>resource</type> and arrays or objects containing
objects couldn't be exported by this function.
Variables of type <type>resource</type> couldn't be exported by this
function.
</para>
</note>
</refsect1>