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
 [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: Mon Jun 17 22:01:28 2024 UTC