reference/var/functions/var-export.xml
0f27fadf81b66268edf545f13891401b4d53cc38
...
...
@@ -10,9 +10,9 @@
10
10
<refsect1 role="description">
11
11
&reftitle.description;
12
12
<methodsynopsis>
13
-
<type>mixed</type><methodname>var_export</methodname>
14
-
<methodparam><type>mixed</type><parameter>expression</parameter></methodparam>
15
-
<methodparam choice="opt"><type>bool</type><parameter>return</parameter><initializer>false</initializer></methodparam>
13
+
<type class="union"><type>string</type><type>null</type></type><methodname>var_export</methodname>
14
+
<methodparam><type>mixed</type><parameter>value</parameter></methodparam>
15
+
<methodparam choice="opt"><type>bool</type><parameter>return</parameter><initializer>&false;</initializer></methodparam>
16
16
</methodsynopsis>
17
17
<simpara>
18
18
<function>var_export</function> gets structured information about the
...
...
@@ -26,7 +26,7 @@
26
26
<para>
27
27
<variablelist>
28
28
<varlistentry>
29
-
<term><parameter>expression</parameter></term>
29
+
<term><parameter>value</parameter></term>
30
30
<listitem>
31
31
<para>
32
32
The variable you want to export.
...
...
@@ -55,11 +55,6 @@
55
55
</para>
56
56
</refsect1>
57
57

58
-
<refsect1 role="notes">
59
-
&reftitle.notes;
60
-
&note.uses-ob;
61
-
</refsect1>
62
-

63
58
<refsect1 role="changelog">
64
59
&reftitle.changelog;
65
60
<para>
...
...
@@ -73,11 +68,21 @@
73
68
</thead>
74
69
<tbody>
75
70
<row>
76
-
<entry>5.1.0</entry>
71
+
<entry>8.2.0</entry>
77
72
<entry>
78
-
Possibility to export classes and arrays containing classes using the
79
-
<link linkend="object.set-state">__set_state()</link> magic
80
-
method.
73
+
Exported class names are now fully qualified; previously, the leading
74
+
backslash was ommitted.
75
+
</entry>
76
+
</row>
77
+
<row>
78
+
<entry>7.3.0</entry>
79
+
<entry>
80
+
Now exports <classname>stdClass</classname> objects as an array cast to
81
+
an object (<code>(object) array( ... )</code>), rather than using the
82
+
nonexistent method <methodname>stdClass::__setState</methodname>.
83
+
The practical effect is that now <classname>stdClass</classname> is
84
+
exportable, and the resulting code will even work on earlier versions of
85
+
PHP.
81
86
</entry>
82
87
</row>
83
88
</tbody>
...
...
@@ -135,7 +140,31 @@ echo $v;
135
140
</para>
136
141
<para>
137
142
<example>
138
-
<title>Exporting classes since PHP 5.1.0</title>
143
+
<title>Exporting stdClass (since PHP 7.3.0)</title>
144
+
<programlisting role="php">
145
+
<![CDATA[
146
+
<?php
147
+
$person = new stdClass;
148
+
$person->name = 'ElePHPant ElePHPantsdotter';
149
+
$person->website = 'https://php.net/elephpant.php';
150
+

151
+
var_export($person);
152
+
]]>
153
+
</programlisting>
154
+
&example.outputs;
155
+
<screen>
156
+
<![CDATA[
157
+
(object) array(
158
+
'name' => 'ElePHPant ElePHPantsdotter',
159
+
'website' => 'https://php.net/elephpant.php',
160
+
)
161
+
]]>
162
+
</screen>
163
+
</example>
164
+
</para>
165
+
<para>
166
+
<example>
167
+
<title>Exporting classes</title>
139
168
<programlisting role="php">
140
169
<![CDATA[
141
170
<?php
...
...
@@ -158,7 +187,7 @@ A::__set_state(array(
158
187
</para>
159
188
<para>
160
189
<example>
161
-
<title>Using <link linkend="object.set-state">__set_state()</link> (since PHP 5.1.0)</title>
190
+
<title>Using <link linkend="object.set-state">__set_state()</link></title>
162
191
<programlisting role="php">
163
192
<![CDATA[
164
193
<?php
...
...
@@ -221,15 +250,17 @@ object(A)#2 (2) {
221
250
</note>
222
251
<warning>
223
252
<para>
224
-
When <function>var_export</function> exports objects, the leading backslash is not included in the class name of namespaced classes for maximum compatibility.
253
+
Prior to PHP 8.2.0, when <function>var_export</function> exports objects,
254
+
the leading backslash is not included in the class name of namespaced classes for maximum compatibility.
225
255
</para>
226
256
</warning>
227
257
<note>
228
258
<para>
229
259
To be able to evaluate the PHP generated by <function>var_export</function>,
230
260
all processed objects must implement the magic <link
231
-
linkend="object.set-state">__set_state</link> method. Note that StdClass
232
-
does not implement __set_state().
261
+
linkend="object.set-state">__set_state</link> method. The only exception is
262
+
<classname>stdClass</classname>, which is exported using an array cast to
263
+
an object.
233
264
</para>
234
265
</note>
235
266
</refsect1>
...
...
@@ -245,7 +276,6 @@ object(A)#2 (2) {
245
276
</para>
246
277
</refsect1>
247
278
</refentry>
248
-

249
279
<!-- Keep this comment at the end of the file
250
280
Local variables:
251
281
mode: sgml
252
282