php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40620 Passing by reference made on the fly does not change and no error reported
Submitted: 2007-02-24 20:55 UTC Modified: 2007-02-26 08:09 UTC
From: mano at easymail dot hu Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.1 OS: Windows XP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mano at easymail dot hu
New email:
PHP Version: OS:

 

 [2007-02-24 20:55 UTC] mano at easymail dot hu
Description:
------------
I had create variables in my PHP4 application in the function-call after php4.4 new reference notice came out. It was actually working in php4.4.4 and the variable could be passed as reference:
test($arr = array("ref"=>1));

I am switching to php5 and neither in php5.1 nor in php5.2 it is working or giving any error message.
I believe this should work, since the variable creation has precedence over the function is passed.
Anyhow, if this is another "unsolvable" problem what is so hard to do engine-wise, at least an error should be dropped like everywhere else saying "Hello, this will NOT work!"

Reproduce code:
---------------
function test(&$arr){
$arr['ref'] = 2;
}
test($myarr = array('ref'=>1));
$myarr2 = array('ref'=>1);
test($myarr2);
print_r($myarr); 
print_r($myarr2); 

Expected result:
----------------
Array ( [ref] => 2 ) Array ( [ref] => 2 )

OR

Notice: Only variable could pass by reference

Actual result:
--------------
Array ( [ref] => 1 ) Array ( [ref] => 2 )

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-02-26 08:09 UTC] tony2001@php.net
Strict Standards: Only variables should be passed by reference in /tmp/4.php on line 8
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 06 09:01:32 2025 UTC