Destructor best practice?

From: Date: Fri, 02 May 2014 14:45:18 +0000
Subject: Destructor best practice?
Groups: php.internals 
Request: Send a blank email to internals+get-73852@lists.php.net to get a copy of this message
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/


Thread (3 messages)

« previous php.internals (#73852) next »