Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:73869 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 65876 invoked from network); 3 May 2014 03:24:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 May 2014 03:24:58 -0000 Authentication-Results: pb1.pair.com smtp.mail=thruska@cubiclesoft.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=thruska@cubiclesoft.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain cubiclesoft.com designates 74.208.44.107 as permitted sender) X-PHP-List-Original-Sender: thruska@cubiclesoft.com X-Host-Fingerprint: 74.208.44.107 u15404699.onlinehome-server.com Received: from [74.208.44.107] ([74.208.44.107:46566] helo=u15404699.onlinehome-server.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A8/47-16678-58164635 for ; Fri, 02 May 2014 23:24:53 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: thruska@cubiclesoft.com) with ESMTPSA id 2107E5000084 Message-ID: <53646179.6000105@cubiclesoft.com> Date: Fri, 02 May 2014 20:24:41 -0700 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:11.0) Gecko/20120327 Thunderbird/11.0.1 MIME-Version: 1.0 To: PHP Development References: <5363AF7E.5040100@cubiclesoft.com> <1399043272.5851.26.camel@guybrush> In-Reply-To: <1399043272.5851.26.camel@guybrush> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Destructor best practice? From: thruska@cubiclesoft.com (Thomas Hruska) On 5/2/2014 8:07 AM, Johannes Schlüter wrote: > On Fri, 2014-05-02 at 07:45 -0700, Thomas Hruska wrote: >> Which is considered best-practice? I'm leaning toward the latter, but >> want to make sure there aren't any issues with relying on the __destruct >> approach. > > My opinion is that __destruct() should "unset" the object state, as it > makes sense, it should exist (unless class is marked final) so users can > reliably call it from child classes. __destruct() should *not* destroy > internal object structures which leaves pointers around etc. but always > leave a defined state. > > The dtor handler should do all required cleanup to ensure there are no > leaks etc. This mostly means cleaning up things the engine can't reach > otherwise (having "struct my_object { zend_object inner; my_ptr_t > *ptr; }" object->ptr should be cleaned up here) > > johannes Thanks! That was very helpful. -- Thomas Hruska CubicleSoft President I've got great, time saving software that you will find useful. http://cubiclesoft.com/