From 8de92952dd746edbca8f851099e25079b9e1418b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Sun, 19 May 2024 21:41:07 +0200 Subject: [PATCH] Add cast_object handler for objects which were recently converted from resources --- ext/odbc/php_odbc.c | 24 ++++++++++++++++++++++++ ext/soap/soap.c | 24 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/ext/odbc/php_odbc.c b/ext/odbc/php_odbc.c index 99bd4e45613..535d2a14fcc 100644 --- a/ext/odbc/php_odbc.c +++ b/ext/odbc/php_odbc.c @@ -186,6 +186,17 @@ static zend_function *odbc_connection_get_constructor(zend_object *object) return NULL; } +static zend_result odbc_connection_cast_object(zend_object *obj, zval *result, int type) +{ + if (type == IS_LONG) { + ZVAL_LONG(result, obj->handle); + + return SUCCESS; + } + + return zend_std_cast_object_tostring(obj, result, type); +} + static void odbc_connection_free_obj(zend_object *obj) { odbc_link *link = odbc_link_from_obj(obj); @@ -218,6 +229,17 @@ static zend_function *odbc_result_get_constructor(zend_object *object) return NULL; } +static zend_result odbc_result_cast_object(zend_object *obj, zval *result, int type) +{ + if (type == IS_LONG) { + ZVAL_LONG(result, obj->handle); + + return SUCCESS; + } + + return zend_std_cast_object_tostring(obj, result, type); +} + static void odbc_result_free(odbc_result *res) { ZEND_ASSERT(res->conn_ptr && "result has already been closed"); @@ -534,6 +556,7 @@ PHP_MINIT_FUNCTION(odbc) odbc_connection_object_handlers.free_obj = odbc_connection_free_obj; odbc_connection_object_handlers.get_constructor = odbc_connection_get_constructor; odbc_connection_object_handlers.clone_obj = NULL; + odbc_connection_object_handlers.cast_object = odbc_connection_cast_object; odbc_connection_object_handlers.compare = zend_objects_not_comparable; odbc_result_ce = register_class_Odbc_Result(); @@ -545,6 +568,7 @@ PHP_MINIT_FUNCTION(odbc) odbc_result_object_handlers.free_obj = odbc_result_free_obj; odbc_result_object_handlers.get_constructor = odbc_result_get_constructor; odbc_result_object_handlers.clone_obj = NULL; + odbc_result_object_handlers.cast_object = odbc_result_cast_object; odbc_result_object_handlers.compare = zend_objects_not_comparable; #if defined(HAVE_IBMDB2) && defined(_AIX) diff --git a/ext/soap/soap.c b/ext/soap/soap.c index d59b34a1e22..e7be6640e81 100644 --- a/ext/soap/soap.c +++ b/ext/soap/soap.c @@ -228,6 +228,17 @@ static zend_function *soap_url_object_get_constructor(zend_object *object) return NULL; } +static zend_result soap_url_cast_object(zend_object *obj, zval *result, int type) +{ + if (type == IS_LONG) { + ZVAL_LONG(result, obj->handle); + + return SUCCESS; + } + + return zend_std_cast_object_tostring(obj, result, type); +} + static inline soap_sdl_object *soap_sdl_object_fetch(zend_object *obj) { return (soap_sdl_object *) ((char *) obj - XtOffsetOf(soap_sdl_object, std)); @@ -264,6 +275,17 @@ static zend_function *soap_sdl_object_get_constructor(zend_object *object) return NULL; } +static zend_result soap_sdl_cast_object(zend_object *obj, zval *result, int type) +{ + if (type == IS_LONG) { + ZVAL_LONG(result, obj->handle); + + return SUCCESS; + } + + return zend_std_cast_object_tostring(obj, result, type); +} + ZEND_DECLARE_MODULE_GLOBALS(soap) static void (*old_error_handler)(int, zend_string *, const uint32_t, zend_string *); @@ -487,6 +509,7 @@ PHP_MINIT_FUNCTION(soap) soap_url_object_handlers.free_obj = soap_url_object_free; soap_url_object_handlers.get_constructor = soap_url_object_get_constructor; soap_url_object_handlers.clone_obj = NULL; + soap_url_object_handlers.cast_object = soap_url_cast_object; soap_url_object_handlers.compare = zend_objects_not_comparable; soap_sdl_class_entry = register_class_Soap_Sdl(); @@ -498,6 +521,7 @@ PHP_MINIT_FUNCTION(soap) soap_sdl_object_handlers.free_obj = soap_sdl_object_free; soap_sdl_object_handlers.get_constructor = soap_sdl_object_get_constructor; soap_sdl_object_handlers.clone_obj = NULL; + soap_url_object_handlers.cast_object = soap_sdl_cast_object; soap_sdl_object_handlers.compare = zend_objects_not_comparable; register_soap_symbols(module_number);