|  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: tobias at olsson dot be
New email:
PHP Version: OS:


 [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.

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() {
  function returnDoh() {
    return $this->doh2;
$tst = new TestObj();
// Shows the value before it's modified
// 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
// here we print the value of $tst->doh2


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-06 14:26 UTC]
This is fixed in new Zend Engine.
 [2002-06-06 14:27 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 05:01:27 2024 UTC