svn: /phpdoc/en/trunk/language/ references.xml
| From: | Gustavo André dos Santos Lopes | Date: | Fri, 22 Oct 2010 23:59:00 +0000 |
| Subject: | svn: /phpdoc/en/trunk/language/ references.xml | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-7295@lists.php.net to get a copy of this message | ||
cataphract Fri, 22 Oct 2010 23:59:00 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=304634
Log:
- Merged text added in rev #304613 with note above.
- Even more evil references+arrays example to stress
the dangerous nature of the combination.
Bug: http://bugs.php.net/304613 (error getting bug
information)
Changed paths:
U phpdoc/en/trunk/language/references.xml
Modified: phpdoc/en/trunk/language/references.xml
===================================================================
--- phpdoc/en/trunk/language/references.xml 2010-10-22 23:27:24 UTC (rev 304633)
+++ phpdoc/en/trunk/language/references.xml 2010-10-22 23:59:00 UTC (rev 304634)
@@ -59,12 +59,6 @@
</para>
<note>
<para>
- If arrays with references are copied, their values are not dereferenced.
- This is valid also for arrays passed by value to functions.
- </para>
- </note>
- <note>
- <para>
If you assign, pass, or return an undefined variable by reference,
it will get created.
<example>
@@ -192,9 +186,10 @@
</para>
<para>
Note, however, that references inside arrays are potentially dangerous.
- While doing a normal (not by reference) assignment with a reference on the
- right side does not turn the left side into a reference, references inside
- arrays are preserved in normal assignments. Example:
+ Doing a normal (not by reference) assignment with a reference on the
+ right side does not turn the left side into a reference, but references
+ inside arrays are preserved in these normal assignments. This also applies
+ to function calls where the array is passed by value. Example:
<informalexample>
<programlisting role="php">
<![CDATA[
@@ -206,8 +201,8 @@
$c = 7; //$c is not a reference; no change to $a or $b
/* Assignment of array variables */
-$a = 1;
-$arr = array(&$a);
+$arr = array(1);
+$a =& $arr[0]; //$a and $arr[0] are in the same reference set
$arr2 = $arr; //not an assignment-by-reference!
$arr2[0]++;
/* $a == 2, $arr == array(2) */