From:             tilman dot giese at gmx dot de
Operating system: Linux
PHP version:      4.3.4
PHP Bug Type:     Variables related
Bug description:  object references get lost

Description:
------------
The problem is not that easy to explain. If you have two objects
referencing each other, one of the references gets somehow lost. Look at
the actual result, especially at the missing ampersands of object(test3)!

Although I only use references in the script (sorry about it be longer
than 20 lines) it seems that I get copies of the objects.

Reproduce code:
---------------
class Test1 {

    var $a;

    function Test1() {

        $this->a = new Test2();
    }

    function &getTest2() {

        return $this->a;
    }
}

class Test2 {

        var $b;

        var $counter = 1;

        function Test2() {

        $this->b = new Test3($this);
    }

    function &getTest3() {

        return $this->b;
    }
}

class Test3 {

        var $p;

        function Test3(&$parent) {

        $parent->counter++;

        $this->p =& $parent;
    }

    function getCounter() {

        return $this->p->counter;
    }
}

$obj = new Test1();
$obj2 =& $obj->getTest2();
echo $obj2->counter;

$obj2->counter++;
$obj3 =& $obj2->getTest3();
echo $obj3->getCounter();

var_dump($obj);

Expected result:
----------------
23

object(test1)(1) {
  ["a"]=>
  &object(test2)(2) {
    ["b"]=>
    &object(test3)(1) {
      ["p"]=>
      &object(test2)(2) {
        ["b"]=>
        &object(test3)(1) {
          ["p"]=>
          &object(test2)(2) {
            ["b"]=>
            &object(test3)(1) {
              ["p"]=>
              *RECURSION*
            }
            ["counter"]=>
            int(3)
          }
        }
        ["counter"]=>
        int(3)
      }
    }
    ["counter"]=>
    int(3)
  }
}


Actual result:
--------------
22

object(test1)(1) {
  ["a"]=>
  &object(test2)(2) {
    ["b"]=>
    &object(test3)(1) {
      ["p"]=>
      &object(test2)(2) {
        ["b"]=>
        object(test3)(1) {
          ["p"]=>
          &object(test2)(2) {
            ["b"]=>
            object(test3)(1) {
              ["p"]=>
              *RECURSION*
            }
            ["counter"]=>
            int(2)
          }
        }
        ["counter"]=>
        int(2)
      }
    }
    ["counter"]=>
    int(3)
  }
}


-- 
Edit bug report at http://bugs.php.net/?id=26756&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=26756&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=26756&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=26756&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=26756&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=26756&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=26756&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=26756&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=26756&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=26756&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=26756&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=26756&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=26756&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=26756&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=26756&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=26756&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=26756&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=26756&r=float

Reply via email to