svn: /phpdoc/ja/trunk/reference/var/functions/ var-export.xml

[email protected] (Yoshinari Takaoka)
Newsgroups php.doc.ja
Message-ID <[email protected]>
mumumu                                   Fri, 28 Feb 2020 17:40:19 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=349261

Log:
var_export: Mention 7.3.0 change for stdClass

Patch by hikari-no-yume.

Changed paths:
    U   phpdoc/ja/trunk/reference/var/functions/var-export.xml

Modified: phpdoc/ja/trunk/reference/var/functions/var-export.xml
===================================================================
--- phpdoc/ja/trunk/reference/var/functions/var-export.xml	2020-02-28 14:00:14 UTC (rev 349260)
+++ phpdoc/ja/trunk/reference/var/functions/var-export.xml	2020-02-28 17:40:19 UTC (rev 349261)
@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!-- $Revision$ -->
 <!-- splitted from ./en/functions/var.xml, last change in rev 1.6 -->
-<!-- EN-Revision: 343899 Maintainer: hirokawa Status: ready -->
-<!-- CREDITS: shimooka -->
+<!-- EN-Revision: 349260 Maintainer: hirokawa Status: ready -->
+<!-- CREDITS: shimooka,mumumu -->
 <refentry xml:id="function.var-export" xmlns="http://docbook.org/ns/docbook">
  <refnamediv>
   <refname>var_export</refname>
@@ -77,6 +77,17 @@
      </thead>
      <tbody>
       <row>
+       <entry>7.3.0</entry>
+       <entry>
+        <classname>stdClass</classname> オブジェクトは、
+        存在しないメソッド <methodname>stdClass::__setState</methodname> を使わず、
+        配列をオブジェクトにキャストした形
+        (<code>(object) array( ... )</code>) でエクスポートされるようになりました。
+        この変更によって、<classname>stdClass</classname> がエクスポート可能になり、
+        このバージョンより前の PHP でもエクスポートした結果が動くようになりました。
+       </entry>
+      </row>
+      <row>
        <entry>5.1.0</entry>
        <entry>
         マジックメソッド
@@ -140,6 +151,30 @@
   </para>
   <para>
    <example>
+    <title>PHP 7.3.0 以降で stdClass をエクスポートする</title>
+    <programlisting role="php">
+<![CDATA[
+<?php
+$person = new stdClass;
+$person->name = 'ElePHPant ElePHPantsdotter';
+$person->website = 'https://php.net/elephpant.php';
+
+var_export($person);
+]]>
+    </programlisting>
+    &example.outputs;
+    <screen>
+<![CDATA[
+(object) array(
+   'name' => 'ElePHPant ElePHPantsdotter',
+   'website' => 'https://php.net/elephpant.php',
+)
+]]>
+    </screen>
+   </example>
+  </para>
+  <para>
+   <example>
     <title>PHP 5.1.0 以降でのクラスのエクスポート</title>
     <programlisting role="php">
 <![CDATA[
@@ -235,7 +270,8 @@
     <function>var_export</function> が生成する PHP を評価できるようにするためには、
     処理対象のすべてのオブジェクトがマジックメソッド <link
     linkend="object.set-state">__set_state</link> を実装している必要があります。
-    StdClass は __set_state() を実装していないことに注意しましょう。
+    これの唯一の例外は <classname>stdClass</classname> です。
+    <classname>stdClass</classname> は、配列をオブジェクトにキャストした形でエクスポートされます。
    </para>
   </note>
  </refsect1>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.