Skip to content

Commit 32dd853

Browse files
morrisonlevinikic
andcommitted
Document .dtor_obj and .free_obj
Closes phpGH-6656. Co-authored-by: Nikita Popov <nikic@php.net>
1 parent 23a7b0f commit 32dd853

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

Zend/zend_object_handlers.h

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,29 @@ typedef zend_array *(*zend_object_get_properties_for_t)(zend_object *object, zen
110110
typedef zend_function *(*zend_object_get_method_t)(zend_object **object, zend_string *method, const zval *key);
111111
typedef zend_function *(*zend_object_get_constructor_t)(zend_object *object);
112112

113-
/* Object maintenance/destruction */
114-
typedef void (*zend_object_dtor_obj_t)(zend_object *object);
113+
/* free_obj should release any resources the object holds, without freeing the
114+
* object structure itself. The object does not need to be in a valid state after
115+
* free_obj finishes running.
116+
*
117+
* free_obj will always be invoked, even if the object leaks or a fatal error
118+
* occurs. However, during shutdown it may be called once the executor is no
119+
* longer active, in which case execution of user code may be skipped.
120+
*/
115121
typedef void (*zend_object_free_obj_t)(zend_object *object);
122+
123+
/* dtor_obj is called before free_obj. The object must remain in a valid state
124+
* after dtor_obj finishes running. Unlike free_obj, it is run prior to
125+
* deactivation of the executor during shutdown, which allows user code to run.
126+
*
127+
* This handler is not guaranteed to be called (e.g. on fatal error), and as
128+
* such should not be used to release resources or deallocate memory. Furthermore,
129+
* releasing resources in this handler can break detection of memory leaks, as
130+
* cycles may be broken early.
131+
*
132+
* dtor_obj should be used *only* to call user destruction hooks, such as __destruct.
133+
*/
134+
typedef void (*zend_object_dtor_obj_t)(zend_object *object);
135+
116136
typedef zend_object* (*zend_object_clone_obj_t)(zend_object *object);
117137

118138
/* Get class name for display in var_dump and other debugging functions.

0 commit comments

Comments
 (0)