2929#include "ext/standard/php_incomplete_class.h"
3030
3131
32- static int le_sdl = 0 ;
3332static int le_typemap = 0 ;
3433
3534typedef struct _soapHeader {
@@ -128,15 +127,13 @@ static void soap_error_handler(int error_num, zend_string *error_filename, const
128127#define FETCH_THIS_SDL (ss ) \
129128 { \
130129 zval *__tmp = Z_CLIENT_SDL_P(ZEND_THIS); \
131- if (Z_TYPE_P(__tmp) == IS_RESOURCE ) { \
132- FETCH_SDL_RES(ss, __tmp); \
130+ if (Z_TYPE_P(__tmp) == IS_OBJECT && instanceof_function(Z_OBJCE_P(__tmp), soap_sdl_class_entry) ) { \
131+ ss = Z_SOAP_SDL_P( __tmp)->sdl ; \
133132 } else { \
134133 ss = NULL; \
135134 } \
136135 }
137136
138- #define FETCH_SDL_RES (ss ,tmp ) ss = (sdlPtr) zend_fetch_resource_ex(tmp, "sdl", le_sdl)
139-
140137#define FETCH_TYPEMAP_RES (ss ,tmp ) ss = (HashTable*) zend_fetch_resource_ex(tmp, "typemap", le_typemap)
141138
142139#define Z_PARAM_NAME_P (zv ) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 0))
@@ -177,9 +174,11 @@ static zend_class_entry* soap_header_class_entry;
177174static zend_class_entry * soap_param_class_entry ;
178175zend_class_entry * soap_var_class_entry ;
179176zend_class_entry * soap_url_class_entry ;
177+ zend_class_entry * soap_sdl_class_entry ;
180178
181179static zend_object_handlers soap_server_object_handlers ;
182180static zend_object_handlers soap_url_object_handlers ;
181+ static zend_object_handlers soap_sdl_object_handlers ;
183182
184183typedef struct {
185184 soapServicePtr service ;
@@ -234,6 +233,43 @@ static zend_function *soap_url_object_get_constructor(zend_object *object)
234233
235234 return NULL ;
236235}
236+
237+ static inline soap_sdl_object * soap_sdl_object_fetch (zend_object * obj )
238+ {
239+ return (soap_sdl_object * ) ((char * ) obj - XtOffsetOf (soap_sdl_object , std ));
240+ }
241+
242+ #define Z_SOAP_SDL_P (zv ) soap_sdl_object_fetch(Z_OBJ_P(zv))
243+
244+ static zend_object * soap_sdl_object_create (zend_class_entry * ce )
245+ {
246+ soap_sdl_object * sdl_obj = zend_object_alloc (sizeof (soap_sdl_object ), ce );
247+
248+ zend_object_std_init (& sdl_obj -> std , ce );
249+ object_properties_init (& sdl_obj -> std , ce );
250+
251+ return & sdl_obj -> std ;
252+ }
253+
254+ static void soap_sdl_object_free (zend_object * obj )
255+ {
256+ soap_sdl_object * sdl_obj = soap_sdl_object_fetch (obj );
257+
258+ if (sdl_obj -> sdl ) {
259+ delete_sdl (sdl_obj -> sdl );
260+ sdl_obj -> sdl = NULL ;
261+ }
262+
263+ zend_object_std_dtor (& sdl_obj -> std );
264+ }
265+
266+ static zend_function * soap_sdl_object_get_constructor (zend_object * object )
267+ {
268+ zend_throw_error (NULL , "Cannot directly construct Soap\\Sdl" );
269+
270+ return NULL ;
271+ }
272+
237273ZEND_DECLARE_MODULE_GLOBALS (soap )
238274
239275static void (* old_error_handler )(int , zend_string * , const uint32_t , zend_string * );
@@ -418,11 +454,6 @@ PHP_RINIT_FUNCTION(soap)
418454 return SUCCESS ;
419455}
420456
421- static void delete_sdl_res (zend_resource * res )
422- {
423- delete_sdl (res -> ptr );
424- }
425-
426457static void delete_hashtable_res (zend_resource * res )
427458{
428459 delete_hashtable (res -> ptr );
@@ -458,7 +489,6 @@ PHP_MINIT_FUNCTION(soap)
458489
459490 soap_header_class_entry = register_class_SoapHeader ();
460491
461- le_sdl = zend_register_list_destructors_ex (delete_sdl_res , NULL , "SOAP SDL" , module_number );
462492 le_typemap = zend_register_list_destructors_ex (delete_hashtable_res , NULL , "SOAP table" , module_number );
463493
464494 soap_url_class_entry = register_class_Soap_Url ();
@@ -472,6 +502,17 @@ PHP_MINIT_FUNCTION(soap)
472502 soap_url_object_handlers .clone_obj = NULL ;
473503 soap_url_object_handlers .compare = zend_objects_not_comparable ;
474504
505+ soap_sdl_class_entry = register_class_Soap_Sdl ();
506+ soap_sdl_class_entry -> create_object = soap_sdl_object_create ;
507+ soap_sdl_class_entry -> default_object_handlers = & soap_sdl_object_handlers ;
508+
509+ memcpy (& soap_sdl_object_handlers , & std_object_handlers , sizeof (zend_object_handlers ));
510+ soap_sdl_object_handlers .offset = XtOffsetOf (soap_sdl_object , std );
511+ soap_sdl_object_handlers .free_obj = soap_sdl_object_free ;
512+ soap_sdl_object_handlers .get_constructor = soap_sdl_object_get_constructor ;
513+ soap_sdl_object_handlers .clone_obj = NULL ;
514+ soap_sdl_object_handlers .compare = zend_objects_not_comparable ;
515+
475516 register_soap_symbols (module_number );
476517
477518 old_error_handler = zend_error_cb ;
@@ -2086,15 +2127,20 @@ PHP_METHOD(SoapClient, __construct)
20862127
20872128 if (wsdl ) {
20882129 int old_soap_version ;
2089- zend_resource * res ;
20902130
20912131 old_soap_version = SOAP_GLOBAL (soap_version );
20922132 SOAP_GLOBAL (soap_version ) = soap_version ;
20932133
20942134 sdl = get_sdl (this_ptr , ZSTR_VAL (wsdl ), cache_wsdl );
2095- res = zend_register_resource (sdl , le_sdl );
20962135
2097- ZVAL_RES (Z_CLIENT_SDL_P (this_ptr ), res );
2136+ zval * sdl_zval = Z_CLIENT_SDL_P (this_ptr );
2137+ if (Z_TYPE_P (sdl_zval ) == IS_OBJECT ) {
2138+ zval_ptr_dtor (sdl_zval );
2139+ }
2140+
2141+ object_init_ex (sdl_zval , soap_sdl_class_entry );
2142+ soap_sdl_object * sdl_object = Z_SOAP_SDL_P (sdl_zval );
2143+ sdl_object -> sdl = sdl ;
20982144
20992145 SOAP_GLOBAL (soap_version ) = old_soap_version ;
21002146 }
@@ -2227,8 +2273,11 @@ static void do_soap_call(zend_execute_data *execute_data,
22272273 }
22282274
22292275 tmp = Z_CLIENT_SDL_P (this_ptr );
2230- if (Z_TYPE_P (tmp ) == IS_RESOURCE ) {
2231- FETCH_SDL_RES (sdl ,tmp );
2276+ if (Z_TYPE_P (tmp ) == IS_OBJECT ) {
2277+ #ifdef ZEND_DEBUG
2278+ ZEND_ASSERT (instanceof_function (Z_OBJCE_P (tmp ), soap_sdl_class_entry ));
2279+ #endif
2280+ sdl = Z_SOAP_SDL_P (tmp )-> sdl ;
22322281 }
22332282
22342283 tmp = Z_CLIENT_TYPEMAP_P (this_ptr );
@@ -2536,14 +2585,13 @@ PHP_METHOD(SoapClient, __soapCall)
25362585/* {{{ Returns list of SOAP functions */
25372586PHP_METHOD (SoapClient , __getFunctions )
25382587{
2539- sdlPtr sdl ;
2540-
2541- FETCH_THIS_SDL (sdl );
2542-
25432588 if (zend_parse_parameters_none () == FAILURE ) {
25442589 RETURN_THROWS ();
25452590 }
25462591
2592+ sdl * sdl ;
2593+ FETCH_THIS_SDL (sdl );
2594+
25472595 if (sdl ) {
25482596 smart_str buf = {0 };
25492597 sdlFunctionPtr function ;
@@ -2562,14 +2610,13 @@ PHP_METHOD(SoapClient, __getFunctions)
25622610/* {{{ Returns list of SOAP types */
25632611PHP_METHOD (SoapClient , __getTypes )
25642612{
2565- sdlPtr sdl ;
2566-
2567- FETCH_THIS_SDL (sdl );
2568-
25692613 if (zend_parse_parameters_none () == FAILURE ) {
25702614 RETURN_THROWS ();
25712615 }
25722616
2617+ sdl * sdl ;
2618+ FETCH_THIS_SDL (sdl );
2619+
25732620 if (sdl ) {
25742621 sdlTypePtr type ;
25752622 smart_str buf = {0 };
0 commit comments