|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2002-06-06 14:26 UTC] mfischer@php.net
[2002-06-06 14:27 UTC] mathieu@php.net
[2002-06-06 14:30 UTC] mathieu@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 17:00:01 2025 UTC |
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();