php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39614 assignment reference returned by function
Submitted: 2006-11-24 09:55 UTC Modified: 2006-11-24 10:09 UTC
From: sailormax at inbox dot lv Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.0 OS: any
Private report: No CVE-ID: None
 [2006-11-24 09:55 UTC] sailormax at inbox dot lv
Description:
------------
PHP 4.x.x, returned value by reference, assign to variable reference. But 5.x.x assign copy of value...

Reproduce code:
---------------
function &ret_ref(&$arr)
{
	return $arr;
}

$arr = array("111111", "2222222", "33333333");
$test = ret_ref($arr);
$test[] = "4444444444";
print_r($arr);


Expected result:
----------------
Array ( [0] => 111111 [1] => 2222222 [2] => 33333333 [3] => 4444444444 )

Actual result:
--------------
Array ( [0] => 111111 [1] => 2222222 [2] => 33333333 )

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-24 10:09 UTC] derick@php.net
If you return by reference, you need to assign the returned value by reference as well. This is also true for PHP 4.4.x, but not earlier versions where this usage would create a memory corruption.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 14:04:04 2025 UTC