#40981 [Opn]: Pass by reference and object assignment problem
| From: | stas@php.net | Date: | Mon, 02 Apr 2007 20:19:43 +0000 |
| Subject: | #40981 [Opn]: Pass by reference and object assignment problem | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-111022@lists.php.net to get a copy of this message | ||
ID: 40981
Updated by: stas@php.net
Reported By: sir dot mordred dot service at gmail dot com
Status: Open
Bug Type: Scripting Engine problem
Operating System: Windows XP, apache 2.0
PHP Version: 4.4.6
New Comment:
Recommended reading:
http://www.php.net/manual/en/language.references.php
http://www.php.net/manual/en/language.references.arent.php
Previous Comments:
------------------------------------------------------------------------
[2007-04-02 20:07:30] 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) {
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=40981&edit=1