From:             [EMAIL PROTECTED]
Operating system: Linux
PHP version:      4.2.1
PHP Bug Type:     Class/Object related
Bug description:  Objects copying

There is a bug with getting copy of object where 1th object has another 2th
object and 2th object has another 3th object.
When i copy 2th object to any variable i must have 2th object in 1th and
2th object in variable. It must be equals but not 2 links to one object.
Look at this code and make changes as recommends in conmment.

<?
class a {
        var $i;
        function a () {
                $this->i = 1;
        }
        function set_i ($p) {
                $this->i = $p;
        }
        function get_i () {
                return $this->i;
        }
}

class b {
        function b () {
                $this->a = new a ();
        }
        function set_id ($p) {
                $this->a->set_i ($p);
        }
        
        function get () {
                return $this->a->get_i ();
        }
}

class c {
        function c () {
                $this->item = new b ();
        }
}

$cat= new c();
$z1 = $cat->item;  // Comment this line
$cat->item->set_id (12);

$z = $cat->item->a;
//$z1 = $cat->item; // Decomment this line
$cat->item->set_id (17);

echo "<br>C: i: ".$cat->item->get();
echo "<br>Z: i: ".$z->get_i ();
echo "<br>Z: i: ".$z1->get ();
if ($cat->item->get() == $z1->get ()) echo " - <font color=red>Getting BUG
here. There must be '1' value!</font>";
?>

-- 
Edit bug report at http://bugs.php.net/?id=17239&edit=1
-- 
Fixed in CVS:        http://bugs.php.net/fix.php?id=17239&r=fixedcvs
Fixed in release:    http://bugs.php.net/fix.php?id=17239&r=alreadyfixed
Need backtrace:      http://bugs.php.net/fix.php?id=17239&r=needtrace
Try newer version:   http://bugs.php.net/fix.php?id=17239&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=17239&r=support
Expected behavior:   http://bugs.php.net/fix.php?id=17239&r=notwrong
Not enough info:     http://bugs.php.net/fix.php?id=17239&r=notenoughinfo
Submitted twice:     http://bugs.php.net/fix.php?id=17239&r=submittedtwice
register_globals:    http://bugs.php.net/fix.php?id=17239&r=globals

Reply via email to