|  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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
49 - 16 = ?
Subscribe to this entry?

 [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: Wed Feb 21 06:01:29 2024 UTC