mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
References with complex arrays (bug #17959)
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@164371 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
3a35f32f02
commit
ab4fd0ca34
1 changed files with 27 additions and 1 deletions
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.30 $ -->
|
||||
<!-- $Revision: 1.31 $ -->
|
||||
<chapter id="language.references">
|
||||
<title>References Explained</title>
|
||||
|
||||
|
@ -117,6 +117,32 @@ echo "var2 is set to '$var2'\n"; // var2 is set to 'Example variable'
|
|||
to <literal>$var</literal> only changes the local variable's reference.
|
||||
</para>
|
||||
</warning>
|
||||
<warning>
|
||||
<para>
|
||||
Complex arrays are sometimes rather copied than referenced. Thus following
|
||||
example will not work as expected.
|
||||
<example>
|
||||
<title>References with complex arrays</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$top = array(
|
||||
'A' => array(),
|
||||
'B' => array(
|
||||
'B_b' => array(),
|
||||
),
|
||||
);
|
||||
|
||||
$top['A']['parent'] = &$top;
|
||||
$top['B']['parent'] = &$top;
|
||||
$top['B']['B_b']['data'] = 'test';
|
||||
print_r($top['A']['parent']['B']['B_b']); // array()
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</para>
|
||||
</warning>
|
||||
<para>
|
||||
The second thing references do is to pass variables
|
||||
by-reference. This is done by making a local variable in a function and
|
||||
|
|
Loading…
Reference in a new issue