ID:               26765
 Updated by:       [EMAIL PROTECTED]
 Reported By:      alex_mailbox53 at yahoo dot com
 Status:           Assigned
 Bug Type:         Zend Engine 2 problem
 Operating System: *
 PHP Version:      5CVS-2004-03-15
 Assigned To:      andi
 New Comment:

Can you please try the latest CVS and see if the crashes persist?
Thanks.

Andi


Previous Comments:
------------------------------------------------------------------------

[2004-04-09 11:06:00] [EMAIL PROTECTED]

Andi, is this a bug or not? 


------------------------------------------------------------------------

[2004-03-10 11:37:20] jaanus at heeringson dot com

Ok, I have found out why the above example occaisionally worked. It
seems the order in which properties are declared play a ignificant
role. I guess the "destruction" propagates along in the order of
declarations. You can try it yourself by swaping two lines in the code
below (the lines are commented).

<pre>
<?php
class factory {
        public $child;

        public function make($class,$parent=null) {
                $_temp=new $class($this);
                $this->child[$class][]=$_temp;
                if(is_object($parent)) {
                        $parent->mount($_temp);
                }
                Return $_temp;
        }
}

class root {
        public $child;  //If the order of these two lines
        public $ref;    //is changed, you get a segfault
        public $parent;

        public function __construct($factory){
                $this->ref['factory']=$factory;
        }

        public function mount($obj){
                $this->child[]=$obj;
                $obj->setParent($this);
                $obj->setRef($this->ref+array('root'=>$this));
        }

        public function setRef($pref) {
                $this->ref=array_merge($pref,$this->ref);
        }

        public function setParent($parent){
                $this->parent=$parent;
        }
}

class child extends root{
        public function mount($obj){
                $this->child[]=$obj;
                $obj->setParent($this);
                $obj->setRef($this->ref+array('child'=>$this));
        }
}

$factory=new factory();
$a=$factory->make('root');
$b=$factory->make('child',$a);
$c=$factory->make('child',$a);
print_r($a);
?>
</pre>

------------------------------------------------------------------------

[2004-03-07 17:46:52] jaanus at heeringson dot com

Actually, you only create 2 objects in the example above, the initial
foo and the bar from foo's constructor. The rest are only references.

I still get the "Segmentation fault (11)", and by debugging my own apps
i can only concurr that this is not solved. I also sometimes get some
kind of race-condition where the apache process heads up to 99.6%, but
this occurs rarely.

How come the "var_dump() to print_r()" matters? I get segfaults without
either (on the sample code). The segfaults only occur the second time
the code is run on the same process, not when initially loading the
page.

------------------------------------------------------------------------

[2004-02-29 16:46:44] awulf at ev1 dot net

-- quoting [EMAIL PROTECTED] 
$t = &new foo();

$t->bar->add(new foo());

var_dump($t);
?>

This yields

object foo is being destroyed.
object bar is being destroyed.
object foo is being destroyed.
object bar is being destroyed.
-- end quote

this looks like it's doing the right thing to me. first you make a foo,
which in its constructor makes a bar. so you have 2 objects. then you
add another foo to the first foo's bar, which then creates another bar,
so you have 4 objects total. then they all get destroyed. looks good to
me, yeah?

------------------------------------------------------------------------

[2004-02-08 22:06:35] [EMAIL PROTECTED]

And several more notes follow.

- It seems circular references are now properly handled 
with the new destructor code recently brought into the 
engine by Zeev.

- As you know, in php5 objects are assigned to variables 
by reference, so it'd be a fair comparison if the 
script goes like this:


<?php
class foo {
    var $bar = false;
    var $parent = false;

    function foo() {
        $this->bar = &new bar($this);
    }
    function __destruct() {
        echo "object ".__CLASS__." is being 
destroyed.\n";
    }
}

class bar {
    var $foo = false;
    var $items  = array();

    function bar(&$foo) {
        $this->foo = &$foo;
    }

    function add(&$item) {
        $this->items[] = &$item;
        $item->parent = &$this->foo;
    }
    function __destruct() {
        echo "object ".__CLASS__." is being 
destroyed.\n";
    }
}

$t = &new foo();

$t->bar->add(new foo());

var_dump($t);
?>

This yields

object foo is being destroyed.
object bar is being destroyed.
object foo is being destroyed.
object bar is being destroyed.

It looks like these objects have been destroyed twice...

- I wasn't able to reproduce the segfault even though I 
changed var_dump() to print_r().


------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/26765

-- 
Edit this bug report at http://bugs.php.net/?id=26765&edit=1

Reply via email to