From 213248a0b91ef1a77aa91e4c91e7927328dcc839 Mon Sep 17 00:00:00 2001 From: Levi Morrison Date: Thu, 30 Mar 2023 17:45:34 -0600 Subject: [PATCH] Document zend_get_op_array_extension_handle This very sharp edge should have been documented long ago. --- Zend/zend_extensions.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Zend/zend_extensions.c b/Zend/zend_extensions.c index ffcd32aa08f..c0c6dc81962 100644 --- a/Zend/zend_extensions.c +++ b/Zend/zend_extensions.c @@ -264,6 +264,27 @@ ZEND_API int zend_get_resource_handle(const char *module_name) } } +/** + * The handle returned by this function can be used with + * `ZEND_OP_ARRAY_EXTENSION(op_array, handle)`. + * + * The extension slot has been available since PHP 7.4 on user functions and + * has been available since PHP 8.2 on internal functions. + * + * # Safety + * The extension slot made available by calling this function is initialized on + * the first call made to the function in that request. If you need to + * initialize it before this point, call `zend_init_func_run_time_cache`. + * + * The function cache slots are not available if the function is a trampoline, + * which can be checked with something like: + * + * if (fbc->type == ZEND_USER_FUNCTION + * && !(fbc->op_array.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) + * ) { + * // Use ZEND_OP_ARRAY_EXTENSION somehow + * } + */ ZEND_API int zend_get_op_array_extension_handle(const char *module_name) { int handle = zend_op_array_extension_handles++; @@ -271,6 +292,7 @@ ZEND_API int zend_get_op_array_extension_handle(const char *module_name) return handle; } +/** See zend_get_op_array_extension_handle for important usage information. */ ZEND_API int zend_get_op_array_extension_handles(const char *module_name, int handles) { int handle = zend_op_array_extension_handles;