Bug #17630 Updated: $obj->get() always returns copy, even with &
| From: | mathieu@php.net | Date: | Thu, 06 Jun 2002 18:30:13 +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-9661@lists.php.net to get a copy of this message | ||
ID: 17630
Updated by: mathieu@php.net
Reported By: tobias@olsson.be
Status: Bogus
Bug Type: Class/Object related
Operating System: Debian unstable Linux 2.4.18
PHP Version: 4.2.1
New Comment:
mfischer:
http://www.php.net/manual/en/language.references.return.php
Previous Comments:
------------------------------------------------------------------------
[2002-06-06 14:27:20] mathieu@php.net
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
------------------------------------------------------------------------
[2002-06-06 14:26:20] mfischer@php.net
This is fixed in new Zend Engine.
------------------------------------------------------------------------
[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