Re: Destructor best practice?
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/
Thread (3 messages)