Bug #63318 [Opn->Nab]: problem with function & reference
Edit report at https://bugs.php.net/bug.php?id=63318&edit=1
ID: 63318
Updated by: cataphract@php.net
Reported by: wojtek77 at o2 dot pl
Summary: problem with function & reference
-Status: Open
+Status: Not a bug
Type: Bug
Package: Arrays related
Operating System: Windows 7
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Not a bug; see http://php.net/manual/en/language.references.whatdo.php
Previous Comments:
------------------------------------------------------------------------
[2012-10-20 14:41:30] wojtek77 at o2 dot pl
Description:
------------
A variable which is an array pass to function as value but this variable behaves
as pass by reference.
Test script:
---------------
/*
* an argument $bar pass to function by value not by reference
*/
function foo($bar)
{
$bar[0] = 'error';
}
/*
* any array variable
*/
$bar[0] = 'OK';
print_r($bar); echo '<br />';
/*
* it will causes an error in function foo()
* create any reference to value of array
*/
$any_reference = & $bar[0];
/*
* although the argument $bar pass to function by value
* it behaves as argument $bar pass to funkction by reference
*/
foo($bar);
print_r($bar); echo '<br />';
Expected result:
----------------
Array ( [0] => OK )
Actual result:
--------------
Array ( [0] => error )
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63318&edit=1
Thread (2 messages)