Skip to content

Commit 9463e5b

Browse files
authored
To supplement an example with an assignment without & for &-function (#4557)
* references.xml To supplement an example with an assignment without & for &-function * Update references.xml Move comments after assignment * Update references.xml Clarify the wording
1 parent 89b506b commit 9463e5b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

language/references.xml

+14
Original file line numberDiff line numberDiff line change
@@ -490,12 +490,26 @@ function &collector()
490490
}
491491
492492
$collection = &collector();
493+
// Now the $collection is a referenced variable that references the static array inside the function
494+
493495
$collection[] = 'foo';
494496
497+
print_r(collector());
498+
// Array
499+
// (
500+
// [0] => foo
501+
// )
502+
495503
?>
496504
]]>
497505
</programlisting>
498506
</informalexample>
507+
<note>
508+
<simpara>
509+
If the assignment is done without the <literal>&amp;</literal> symbol, e.g. <code>$collection = collector();</code>,
510+
the <varname>$collection</varname> variable will receive a copy of the value, not the reference returned by the function.
511+
</simpara>
512+
</note>
499513
To pass the returned reference to another function expecting a reference
500514
you can use this syntax:
501515
<informalexample>

0 commit comments

Comments
 (0)