Hi there...

I was playing a bit with PHP5 and I found some strange behaviours or I just
don't understand....

If I have two classes

PHP Code:
 
class A
{
function 
__construct()
{
     print(
"A constructor called!<br>");
}
 
function 
__destruct()
{
     print(
"A destructor called!<br>");
}
}
 
class 
B
{
function 
__construct()
{
     print(
"B constructor called!<br>");
}
 
function 
__destruct()
{
     print(
"B destructor called!<br>");
}

to begin with testing I stated:

PHP Code:
$a = new A();
$b = new B(); 
which gave me a pretty odd output....

then I tried with references(although that's depricated in php5)
PHP Code:
$a = &new A();
$b = &new B(); 
in both cases B destructor was called after A destructor.....

but isn't the one of main rules in OOP that objects have to be destroyed in the order they were created!?

so I would expect

A constructor called!
B constructor called!
B destructor called!
A destructor called!

Any thoughts on that!?