Skip to content

Commit 213248a

Browse files
authored
Document zend_get_op_array_extension_handle
This very sharp edge should have been documented long ago.
1 parent 930db2b commit 213248a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Zend/zend_extensions.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,35 @@ ZEND_API int zend_get_resource_handle(const char *module_name)
264264
}
265265
}
266266

267+
/**
268+
* The handle returned by this function can be used with
269+
* `ZEND_OP_ARRAY_EXTENSION(op_array, handle)`.
270+
*
271+
* The extension slot has been available since PHP 7.4 on user functions and
272+
* has been available since PHP 8.2 on internal functions.
273+
*
274+
* # Safety
275+
* The extension slot made available by calling this function is initialized on
276+
* the first call made to the function in that request. If you need to
277+
* initialize it before this point, call `zend_init_func_run_time_cache`.
278+
*
279+
* The function cache slots are not available if the function is a trampoline,
280+
* which can be checked with something like:
281+
*
282+
* if (fbc->type == ZEND_USER_FUNCTION
283+
* && !(fbc->op_array.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)
284+
* ) {
285+
* // Use ZEND_OP_ARRAY_EXTENSION somehow
286+
* }
287+
*/
267288
ZEND_API int zend_get_op_array_extension_handle(const char *module_name)
268289
{
269290
int handle = zend_op_array_extension_handles++;
270291
zend_add_system_entropy(module_name, "zend_get_op_array_extension_handle", &zend_op_array_extension_handles, sizeof(int));
271292
return handle;
272293
}
273294

295+
/** See zend_get_op_array_extension_handle for important usage information. */
274296
ZEND_API int zend_get_op_array_extension_handles(const char *module_name, int handles)
275297
{
276298
int handle = zend_op_array_extension_handles;

0 commit comments

Comments
 (0)