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 this is not your bug, you can add a comment by following this link.
If this is your bug, but 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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Wed Jun 26 15:01:30 2024 UTC