#26765 [Asn]: Objects destroyed twice?

From: Date: Wed, 26 May 2004 15:03:48 +0000
Subject: #26765 [Asn]: Objects destroyed twice?
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-60009@lists.php.net to get a copy of this message
 ID:               26765
 User updated by:  alex_mailbox53 at yahoo dot com
 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:

Sorry, I did download the CVS version yet. I tested the issue with PHP5
RC2 and it works Ok - bug is fixed.

Thank you!

Alexander


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

[2004-05-23 22:38:07] andi@php.net

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

Andi

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

[2004-04-09 11:06:00] sniper@php.net

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 moriyoshi@php.net 
$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?

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

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


Thread (14 messages)

« previous php.bugs (#60009) next »