svn: /phpdoc/en/trunk/reference/array/functions/ list.xml
| From: | Christoph Michael Becker | Date: | Sat, 25 Jun 2016 16:10:15 +0000 |
| Subject: | svn: /phpdoc/en/trunk/reference/array/functions/ list.xml | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-14252@lists.php.net to get a copy of this message | ||
cmb Sat, 25 Jun 2016 16:10:15 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=339494
Log:
Fix #65221: Does not adequately explain nature of how list retrieves values from an array
Bug: https://bugs.php.net/65221 (Open) Does not adequately
explain nature of how list retrieves values from an array
Changed paths:
U phpdoc/en/trunk/reference/array/functions/list.xml
Modified: phpdoc/en/trunk/reference/array/functions/list.xml
===================================================================
--- phpdoc/en/trunk/reference/array/functions/list.xml 2016-06-25 15:36:17 UTC (rev 339493)
+++ phpdoc/en/trunk/reference/array/functions/list.xml 2016-06-25 16:10:15 UTC (rev 339494)
@@ -17,6 +17,36 @@
but a language construct. <function>list</function> is used to
assign a list of variables in one operation.
</para>
+ <note>
+ <para>
+ <function>list</function> only works on numerical arrays and assumes
+ the numerical indices start at 0.
+ </para>
+ </note>
+ <warning>
+ <para>
+ In PHP 5, <function>list</function> assigns the values starting with the
+ right-most parameter. In PHP 7, <function>list</function> starts with the
+ left-most parameter.
+ </para>
+ <para>
+ If you are using plain variables, you don't have to worry about this. But
+ if you are using arrays with indices you usually expect the order of the
+ indices in the array the same you wrote in the <function>list</function>
+ from left to right, which is not the case in PHP 5, as it's assigned in the
+ reverse order.
+ </para>
+ <para>
+ Generally speaking, it is advisable to avoid relying on a specific order
+ of operation, as this may change again in the future.
+ </para>
+ </warning>
+ <warning>
+ <para>
+ Modification of the array during <function>list</function> execution (e.g.
+ using <literal>list($a, $b) = $b</literal>) results in undefined behavior.
+ </para>
+ </warning>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
@@ -197,40 +227,47 @@
</screen>
</example>
</para>
+ <para>
+ <example>
+ <title><function>list</function> and order of index definitions</title>
+ <simpara>
+ The order in which the indices of the array to be consumed by
+ <function>list</function> are defined is irrelevant.
+ </simpara>
+ <programlisting role="php">
+<![CDATA[
+<?php
+$foo = array(2 => 'a', 'foo' => 'b', 0 => 'c');
+$foo[1] = 'd';
+list($x, $y, $z) = $foo;
+var_dump($foo, $x, $y, $z);
+]]>
+ </programlisting>
+ <para>
+ Gives the following output (note the order of the elements compared in
+ which order they were written in the <function>list</function> syntax):
+ </para>
+ <screen>
+<![CDATA[
+array(4) {
+ [2]=>
+ string(1) "a"
+ ["foo"]=>
+ string(1) "b"
+ [0]=>
+ string(1) "c"
+ [1]=>
+ string(1) "d"
+}
+string(1) "c"
+string(1) "d"
+string(1) "a"
+]]>
+ </screen>
+ </example>
+ </para>
</refsect1>
- <refsect1 role="notes">
- &reftitle.notes;
- <warning>
- <para>
- In PHP 5, <function>list</function> assigns the values starting with the
- right-most parameter. In PHP 7, <function>list</function> starts with the
- left-most parameter.
- </para>
- <para>
- If you are using plain variables, you don't have to worry about this. But
- if you are using arrays with indices you usually expect the order of the
- indices in the array the same you wrote in the <function>list</function>
- from left to right, which is not the case in PHP 5, as it's assigned in the
- reverse order.
- </para>
- <para>
- Generally speaking, it is advisable to avoid relying on a specific order
- of operation, as this may change again in the future.
- </para>
- </warning>
- <warning>
- <para>
- Modification of the array during <function>list</function> execution (e.g.
- using <literal>list($a, $b) = $b</literal>) results in undefined behavior.
- </para>
- </warning>
- <note>
- <para>
- <function>list</function> only works on numerical arrays and assumes
- the numerical indices start at 0.
- </para>
- </note>
- </refsect1>
+
<refsect1 role="seealso">
&reftitle.seealso;
<para>