From ab4fd0ca3452e59adf8c52cafd0d9462c154dc21 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Mon, 26 Jul 2004 20:53:56 +0000 Subject: [PATCH] References with complex arrays (bug #17959) git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@164371 c90b9560-bf6c-de11-be94-00142212c4b1 --- language/references.xml | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/language/references.xml b/language/references.xml index 0e18f190a4..9cd21d9080 100644 --- a/language/references.xml +++ b/language/references.xml @@ -1,5 +1,5 @@ - + References Explained @@ -117,6 +117,32 @@ echo "var2 is set to '$var2'\n"; // var2 is set to 'Example variable' to $var only changes the local variable's reference. + + + Complex arrays are sometimes rather copied than referenced. Thus following + example will not work as expected. + + References with complex arrays + + 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() +?> +]]> + + + + The second thing references do is to pass variables by-reference. This is done by making a local variable in a function and