Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:73852 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 7134 invoked from network); 2 May 2014 14:45:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 May 2014 14:45:29 -0000 Authentication-Results: pb1.pair.com header.from=thruska@cubiclesoft.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=thruska@cubiclesoft.com; spf=pass; 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:42386] helo=u15404699.onlinehome-server.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 44/FC-16678-48FA3635 for ; Fri, 02 May 2014 10:45:28 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: thruska@cubiclesoft.com) with ESMTPSA id 24F6B5000084 Message-ID: <5363AF7E.5040100@cubiclesoft.com> Date: Fri, 02 May 2014 07:45:18 -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 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Destructor best practice? From: thruska@cubiclesoft.com (Thomas Hruska) There appear to be two different ways that I can free an internal structure when dealing with classes. The first is to declare a 'zend_objects_destroy_object' handler: ... retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, my_free_function_callback, NULL TSRMLS_CC); retval.handlers = zend_get_std_object_handlers(); ... In which 'my_free_function_callback' is the callback that frees underlying structure information. The alternative is to use __destruct: PHP_METHOD(my_class, __destruct) { } ... static const zend_function_entry my_class_methods[] = { ... PHP_ME(my_class, __destruct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR) ... }; 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. -- Thomas Hruska CubicleSoft President I've got great, time saving software that you will find useful. http://cubiclesoft.com/