ID:               39276
 User updated by:  plyrvt at mail dot ru
 Reported By:      plyrvt at mail dot ru
 Status:           Open
 Bug Type:         Variables related
 Operating System: any
 PHP Version:      5.1.6
 New Comment:

Sorry, 1a & 1b were messed up. Correct is:

1a. Element of an array is passed 'by value' and can be modified
independently
1b. Whole array can not be passed 'by value'. It is forced to be passed
by reference.


Previous Comments:
------------------------------------------------------------------------

[2006-10-27 09:56:57] plyrvt at mail dot ru

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"


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=39276&edit=1

Reply via email to