- Messages
- 5,609
- Reaction score
- 250
- Points
- 63
This code:
Produces this output:
The problem being the two last lines of output. The problem is related to d::b. Removing d::b causes everything to destruct correctly, but also completely ruins the functionality of what I'm trying to do
It won't hurt my program to have b and a destruct twice, as long as they destruct after d, but I'd like to know why, if possible
Edit:
And for your time, 332 credits to whomever solves it (and some rep)
Code:
<?php
abstract class a {
public function __construct () {
echo 'constructing ', __CLASS__, '<br/>';
}
public function __destruct() {
echo 'destructing ', __CLASS__, '<br/>';
}
}
class b extends a {
public function __construct() {
echo 'constructing ', __CLASS__, '<br/>';
parent::__construct();
}
public function __destruct() {
echo 'destructing ', __CLASS__, '<br/>';
parent::__destruct();
}
}
class d {
public function __construct() {
echo 'constructing ', __CLASS__, '<br/>';
$this->b = new b();
}
public function __destruct() {
echo 'destructing ', __CLASS__, '<br/>';
$this->b->__destruct();
unset($this->b);
}
public $b;
}
new d();
?>
Code:
constructing d
constructing b
constructing a
destructing d
destructing b
destructing a
[B]destructing b[/B]
[B]destructing a[/B]
It won't hurt my program to have b and a destruct twice, as long as they destruct after d, but I'd like to know why, if possible
Edit:
And for your time, 332 credits to whomever solves it (and some rep)
Last edited: