php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63318 problem with function & reference
Submitted: 2012-10-20 14:41 UTC Modified: 2012-10-20 18:16 UTC
From: wojtek77 at o2 dot pl Assigned:
Status: Not a bug Package: Arrays related
PHP Version: Irrelevant OS: Windows 7
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
28 - 11 = ?
Subscribe to this entry?

 
 [2012-10-20 14:41 UTC] 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 ) 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-10-20 18:16 UTC] cataphract@php.net
-Status: Open +Status: Not a bug
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Nov 25 09:01:23 2020 UTC