php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40981 Pass by reference and object assignment problem
Submitted: 2007-04-02 20:07 UTC Modified: 2007-04-03 08:32 UTC
From: sir dot mordred dot service at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.4.6 OS: Windows XP, apache 2.0
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: sir dot mordred dot service at gmail dot com
New email:
PHP Version: OS:

 

 [2007-04-02 20:07 UTC] sir dot mordred dot service at gmail dot com
Description:
------------
If a parameter passed by reference to a function is assigned a new object with the =& operator, after the function call the variable passed to the function will not contain the object, but its previous value (or null). Assignment with = works fine.

Reproduce code:
---------------
<pre><?php

class A {}

function Foo(&$param)
{
	$param =& new A();
}

function Bar(&$param)
{
	$param = new A();
}

echo phpversion()."\n";

$p = 1;
Foo($p);
var_dump($p);

$q = 1;
Bar($q);
var_dump($q);

?>


Expected result:
----------------
4.4.6
object(a)(0) {
}
object(a)(0) {
}

Actual result:
--------------
4.4.6
int(1)
object(a)(0) {
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-04-03 08:32 UTC] sir dot mordred dot service at gmail dot com
Got it, sorry, my bad. Changing status to "Bogus".
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 04:01:36 2025 UTC