|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-10-27 10:06 UTC] plyrvt at mail dot ru
[2006-10-27 10:13 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 01 08:00:02 2025 UTC |
Description: ------------ Depending on context, references can have 3 different behaviours: 1. Reference to element of an array. Element becomes reference automatically until that reference exist. 1a. Whole array is passed 'by value' and keys of array copy can be modified independently 1b. Element of an array can not be passed 'by value'. It is forced to be passed by reference. 2. Reference to regular variable. Variable does not become reference and can be passed 'by value' Reproduce code: --------------- <?php function bla1($param){ $param['k1']="new!"; } function bla2($param){ $param="new!";} $a['k1']='foo';; echo var_dump($a); echo "<hr>"; $v=&$a['k1']; echo var_dump($a); echo "<hr>"; bla2($a['k1']); echo var_dump($a); echo "<hr>"; bla1($a); echo var_dump($a); echo "<hr>"; unset($v); echo var_dump($a); echo "<hr>"; $k1='foo'; echo var_dump($k1); echo "<hr>"; $v=&$k1; echo var_dump($k1); echo "<hr>"; bla2($k1); echo var_dump($k1); echo "<hr>"; unset($v); echo var_dump($k1); ?> Expected result: ---------------- any predictable output Actual result: -------------- array(1) { ["k1"]=> string(3) "foo" } array(1) { ["k1"]=> &string(3) "foo" } array(1) { ["k1"]=> &string(3) "foo" } array(1) { ["k1"]=> &string(4) "new!" } array(1) { ["k1"]=> string(4) "new!" } -------------- string(3) "foo" string(3) "foo" string(3) "foo" string(3) "foo"