php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #17630 $obj->get() always returns copy, even with &
Submitted: 2002-06-06 14:17 UTC Modified: 2002-06-06 14:30 UTC
From: tobias at olsson dot be Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 4.2.1 OS: Debian unstable Linux 2.4.18
Private report: No CVE-ID: None
 [2002-06-06 14:17 UTC] tobias at olsson dot 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();

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-06 14:26 UTC] mfischer@php.net
This is fixed in new Zend Engine.
 [2002-06-06 14:27 UTC] 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


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Oct 13 05:01:27 2024 UTC