com doc/ja: Added protected property example for Object To Array conversion: language/types/array.xml

From: Date: Tue, 23 Feb 2021 12:37:23 +0000
Subject: com doc/ja: Added protected property example for Object To Array conversion: language/types/array.xml
Groups: php.doc.ja 
Request: Send a blank email to doc-ja+get-6217@lists.php.net to get a copy of this message
Commit: 81f9298297b269b458d89c76ca1f6011d7b35d66 Author: Yoshinari Takaoka <mumumu@mumumu.org> Tue, 23 Feb 2021 21:37:23 +0900 Parents: cabf90c7d1781965c783b2ffeb233966db6cc3d4 Branches: master Link: http://git.php.net/?p=doc/ja.git;a=commitdiff;h=81f9298297b269b458d89c76ca1f6011d7b35d66 Log: Added protected property example for Object To Array conversion Co-authored-by: Christoph M. Becker <cmbecker69@gmx.de> Closes GH-453. Changed paths: M language/types/array.xml Diff: diff --git a/language/types/array.xml b/language/types/array.xml index 89830b409a..7c63b7c11a 100644 --- a/language/types/array.xml +++ b/language/types/array.xml @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <!-- $Revision$ --> -<!-- EN-Revision: 6de2e5772f11997fb9a8c0fa2406fbb2c73b3579 Maintainer: takagi Status: ready --> +<!-- EN-Revision: 3801e08ff8007bcdc2fb2508f2065d130bfec58f Maintainer: takagi Status: ready --> <!-- CREDITS: hirokawa,shimooka,mumumu --> <sect1 xml:id="language.types.array"> <title>配列</title> @@ -826,7 +826,40 @@ $error_descriptions[8] = "This is just an informal notice"; private 変数の場合、変数名の頭にクラス名がつきます。また、 protected 変数の場合は、変数名の頭に '*' がつきます。 このとき、頭に追加される値の前後に null バイトがついてきます。 - その結果、予期せぬ振る舞いをすることがあります。 + </para> + + <informalexample> + <programlisting role="php"> + <![CDATA[ +<?php +class A { + private $B; + protected $C; + public $D; + function __construct() + { + $this->{1} = null; + } +} +var_export((array) new A()); +?> +]]> + </programlisting> + &example.outputs; + <screen> + <![CDATA[ +array ( + '' . "\0" . 'A' . "\0" .. 'B' => NULL, + '' . "\0" . '*' . "\0" . 'C' => NULL, + 'D' => NULL, + 1 => NULL, +) +]]> + </screen> + </informalexample> + + <para> + その結果、以下のような予期せぬ振る舞いをすることがあります: </para> <informalexample> @@ -847,6 +880,19 @@ var_dump((array) new B()); ?> ]]> </programlisting> + &example.outputs; + <screen> + <![CDATA[ +array(3) { + ["BA"]=> + NULL + ["AA"]=> + NULL + ["AA"]=> + NULL +} +]]> + </screen> </informalexample> <para>

« previous php.doc.ja (#6217) next »