destructor sequence explained



Hello
Can someone please help explain how the order of object destructors called
at shutdown is determined, especially with regards to objects composed
of other objects?

For example in the code below, the first example calls the destructors
exactly in the order I would expect. Since object B is still
referenced by object A, A is destroyed first, then B. However in the
second example, it appears that object B is destroyed before object A,
even though A still references B. Can someone please shed some light
on this? Thanks.
James

<?php


class A{

public function __construct($b){
$this->b = $b;

}

public function __destruct(){
echo __class__ . " destroyed\n";
}
}
class B{
public function __destruct(){
echo __class__ . " destroyed\n";
}
}

$b = new B();
$a = new A($b);


?>


Outputs:
A destroyed
B destroyed



However if I add the


class A{

public function __construct($b){
$this->b = $b;
$this->myself = $this; // <--- This is the only change
}

public function __destruct(){
echo __class__ . " destroyed\n";
}
}
class B{
public function __destruct(){
echo __class__ . " destroyed\n";
}
}

$b = new B();
$a = new A($b);


?>

That outputs:
B destroyed
A destroyed
.



Relevant Pages

  • Re: Halt screen startling inexperienced users
    ... >place of the SetValue action in your macro, ... RunCode action (we'll ... >Public Function MakeFormInvisible() ... >> I checked my references in VBA again. ...
    (microsoft.public.access.macros)
  • Can I set a variable reference to a form that is referenced by a variable?
    ... Public Function LoadQualityFactors(varTheReviewID As ... strTheForm As String) As Boolean ... Set frmTheForm = Forms! ... it would be possible to use variable references to point to ...
    (microsoft.public.access.formscoding)
  • Re: Comparing Two Identical Tables - Loop Through fields in a Recordset
    ... by putting the new public function in a standard ... but when I run the query Access tells me that there is an ... 'Undefined Function 'NullIfEqual' in the expression' ... ... references in the Visual Basic Editor ... ...
    (comp.databases.ms-access)
  • Re: Loading/using a type library
    ... References, so the compiler doesn't know it's going to be there. ... Public Function CheckLibraryAs Boolean ... Dim obj As Object ...
    (microsoft.public.vb.general.discussion)
  • Re: UDF Question
    ... (remove nothere from email address if mailing direct) ... public function foo ...
    (microsoft.public.excel.programming)