Bug #17630: $obj->get() always returns copy, even with &
| From: | tobias at olsson dot be | Date: | Thu, 06 Jun 2002 18:17:27 +0000 |
| Subject: | Bug #17630: $obj->get() always returns copy, even with & | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-9658@lists.php.net to get a copy of this message | ||
From: tobias@olsson.be
Operating system: Debian unstable Linux 2.4.18
PHP version: 4.2.1
PHP Bug Type: Class/Object related
Bug description: $obj->get() always returns copy, even with &
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 bug report at http://bugs.php.net/?id=17630&edit=1
--
Fixed in CVS: http://bugs.php.net/fix.php?id=17630&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=17630&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=17630&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=17630&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=17630&r=support
Expected behavior: http://bugs.php.net/fix.php?id=17630&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=17630&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=17630&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=17630&r=globals