Bug #17630 Updated: $obj->get() always returns copy, even with &
| From: | mfischer@php.net | Date: | Thu, 06 Jun 2002 18:26:20 +0000 |
| Subject: | Bug #17630 Updated: $obj->get() always returns copy, even with & | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-9659@lists.php.net to get a copy of this message | ||
ID: 17630
Updated by: mfischer@php.net
Reported By: tobias@olsson.be
-Status: Open
+Status: Closed
Bug Type: Class/Object related
Operating System: Debian unstable Linux 2.4.18
PHP Version: 4.2.1
New Comment:
This is fixed in new Zend Engine.
Previous Comments:
------------------------------------------------------------------------
[2002-06-06 14:17:26] tobias@olsson.be
This script illustrates the problem.
The problem is that if I call on an objects method to return an object,
it will _always_ return a copy. Even if I use the "&" trick, it will
still return a copy.
as the manual states, it is possible to do $obj = &func(); and get a
reference, so it should be possible to do $obj_ref = &$obj->func() and
get a reference.
<?PHP
foreach($array as $key=>$value) { $$key = $value;}
// this object is the object to be modified
class TestObj2 {
var $doh = 1;
function zeroDoh() {
$this->doh = 0;
}
}
// class to just contain an object
class TestObj {
var $doh2;
function TestObj() {
$this->doh2 = new TestObj2();
}
function printDoh() {
echo($this->doh2->doh);
}
function returnDoh() {
return $this->doh2;
}
}
$tst = new TestObj();
// Shows the value before it's modified
$tst->printDoh();
// here we _should_ get a reference to the object $doh2 inside $tst
$tst2 = &$tst->returnDoh();
// here we _should_ be modifiyng the same object as $tst->$doh2, but we
are not
$tst2->zeroDoh();
// here we print the value of $tst->doh2
$tst->printDoh();
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=17630&edit=1