1
0
mirror of https://github.com/php/doc-en.git synced 2026-03-23 23:32:18 +01:00

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
This commit is contained in:
Mikhail Alferov
2025-04-09 04:40:27 +03:00
committed by GitHub
parent 89b506b5b6
commit 9463e5b660

View File

@@ -490,12 +490,26 @@ function &collector()
}
$collection = &collector();
// Now the $collection is a referenced variable that references the static array inside the function
$collection[] = 'foo';
print_r(collector());
// Array
// (
// [0] => foo
// )
?>
]]>
</programlisting>
</informalexample>
<note>
<simpara>
If the assignment is done without the <literal>&amp;</literal> symbol, e.g. <code>$collection = collector();</code>,
the <varname>$collection</varname> variable will receive a copy of the value, not the reference returned by the function.
</simpara>
</note>
To pass the returned reference to another function expecting a reference
you can use this syntax:
<informalexample>