Re: unset( $anobject) does not invoce __destruct()

Re: unset( $anobject) does not invoce __destruct()

am 24.08.2009 15:21:20 von Ashley Sheridan

On Mon, 2009-08-24 at 15:13 +0200, Ralph Deffke wrote:
> that is correct and that is the problem, and even that is not all !!!
>
> try this
> >
>
> abstract class a {
> public function __construct(){
> echo "constructing....
";
> }
> public function __detruct(){
> echo "destructing....
";
> }
> }
>
> class b extends a{
>
> }
> $c = new b();
> unset( $c );
> ?>
>
> the constructor is inherited, the destructor not !!
>
> PHP 5.2.9-1 and
> PHP 5.3.0 behave the same
>
> las trampas de la vida
>
>
>
> ralph_deffke@yahoo.de
>
>
>
> "Stuart" wrote in message
> news:a5f019de0908240606x5fdca70bkb31dd32b072e52b6@mail.gmail .com...
> > 2009/8/24 kranthi :
> > > unset($obj) always calls the __destruct() function of the class.
> > >
> > > in your case clearly you are missing something else. Probably
> > > unset($anobject) is not being called at all ?
> >
> > That's not entirely correct. PHP uses reference counting, so if
> > unsetting a variable did not cause the object to be destructed then
> > it's highly likely that there is another variable somewhere that is
> > holding a reference to that object.
> >
> > -Stuart
> >
> > --
> > http://stut.net/
>
>
>
That would seem sensible to me though really. A constructor only bears
true for the base class, so any classes which inherit it must
incorporate all the constructor parts. A destructor doesn't know about
further classes which will need to inherit it, so it shouldn't be
inherited and the new class should sort things out. At least, that's how
I see it.

Thanks,
Ash
http://www.ashleysheridan.co.uk




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: unset( $anobject) does not invoce __destruct()

am 25.08.2009 00:32:03 von Lupus Michaelis

Ashley Sheridan wrote:

> That would seem sensible to me though really. A constructor only bears
> true for the base class, so any classes which inherit it must
> incorporate all the constructor parts. A destructor doesn't know about
> further classes which will need to inherit it, so it shouldn't be
> inherited and the new class should sort things out. At least, that's how
> I see it.

No, destructor can be set in abstract class. And it must if some
advanced stuff done in the base classe. Like freeing ressources, closing
file or database connections that is generic for classes that implements
abstract stuff.

So said, the __destuct destructor isn't called, for obvious reasons
explained further.

--
Mickaƫl Wolff aka Lupus Michaelis
http://lupusmic.org

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php