php-general Digest 7 Dec 2012 08:11:09 -0000 Issue 8057

Topics (messages 319807 through 319808):

Unset and __destruct
        319807 by: Pierre du Plessis
        319808 by: Sebastian Krebs

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
Hi all

I searched the internet (probably not hard enough), and couldn't find a
decent answer.

I was wondering why, when calling unset on an object, it doesn't
automatically call the __destruct method (if it exists) on the object.

When unsetting an object, php doesn't automatically remove references to
other objects, and you need to manually call the __destruct method where
you can remove any references to other objects.

I know there is a lot of discussion around this topic, but couldn't find a
definate answer as to why this isn't the default behaviour.

Any clarification would greatly be appreciated.

--- End Message ---
--- Begin Message ---
2012/12/6 Pierre du Plessis <pie...@pcservice.co.za>

> Hi all
>
> I searched the internet (probably not hard enough), and couldn't find a
> decent answer.
>
> I was wondering why, when calling unset on an object, it doesn't
> automatically call the __destruct method (if it exists) on the object.
>

Thats because it was never intended :) The engine calls __destruct() right
before the GC frees the object, but unset() only decrease the refcount. The
next time the GC runs it will call the destructor and everythings fine


>
> When unsetting an object, php doesn't automatically remove references to
> other objects, and you need to manually call the __destruct method where
> you can remove any references to other objects.
>

Why? When the GC removes the object from the memory (which might be
slightly later) it also removes the references to associated objects and
when their refcount reaches 0 they will get removed as well. Whats the
problem?


>
> I know there is a lot of discussion around this topic, but couldn't find a
> definate answer as to why this isn't the default behaviour.
>

Why should it? Thats the way a GC works :?


>
> Any clarification would greatly be appreciated.
>



-- 
github.com/KingCrunch

--- End Message ---

Reply via email to