ID:               49962
 Updated by:       [email protected]
 Reported By:      diego at ditech dot com dot br
-Status:           Open
+Status:           Bogus
 Bug Type:         Class/Object related
 Operating System: Windows XP SP3
 PHP Version:      5.2.11
 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php




Previous Comments:
------------------------------------------------------------------------

[2009-10-22 18:28:29] diego at ditech dot com dot br

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)
}

------------------------------------------------------------------------

[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

Reply via email to