ID: 49962
Comment by: diego at ditech dot com dot br
Reported By: diego at ditech dot com dot br
Status: Open
Bug Type: Class/Object related
Operating System: Windows XP SP3
PHP Version: 5.2.11
New Comment:
By the way, it is possible to change object attributes as if both were
passed by reference.
class foo {
public $bar;
}
function change($obj) {
$obj->bar = 1;
$obj = null;
}
$o = new foo;
change($o);
var_dump($o);
The result of this is:
object(foo)#1 (1) {
["bar"] => int(1)
}
Previous Comments:
------------------------------------------------------------------------
[2009-10-22 18:16:18] diego at ditech dot com dot br
Description:
------------
When trying to reassign an object inside a function, it is not acting
as passed by reference.
Reproduce code:
---------------
<?php
class foo {
}
function change($obj) {
$obj = null;
}
function change_ref(&$obj) {
$obj = null;
}
$o = new foo;
change($o);
var_dump($o);
change_ref($o);
var_dump($o);
Expected result:
----------------
Both should yield the same result.
1st: NULL
2nd: NULL
Actual result:
--------------
Only change_ref is redefining the object.
1st:
object(foo)#1 (0) {
}
2nd: NULL
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=49962&edit=1