Skip to content

Commit 66d6c68

Browse files
committed
[skip ci] use zend_call_method_if_exists() instead
1 parent ae13fe0 commit 66d6c68

File tree

1 file changed

+37
-31
lines changed

1 file changed

+37
-31
lines changed

ext/soap/soap.c

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,14 +1454,9 @@ PHP_METHOD(SoapServer, handle)
14541454
service->soap_headers_ptr = &soap_headers;
14551455

14561456
zval *soap_obj = NULL;
1457-
zend_object *soap_zobj = NULL;
1458-
zend_class_entry *soap_obj_ce = NULL;
1459-
HashTable *function_table;
1457+
HashTable *function_table = NULL;
14601458
if (service->type == SOAP_OBJECT) {
14611459
soap_obj = &service->soap_object;
1462-
soap_zobj = Z_OBJ_P(soap_obj);
1463-
soap_obj_ce = Z_OBJCE_P(soap_obj);
1464-
function_table = &soap_obj_ce->function_table;
14651460
} else if (service->type == SOAP_CLASS) {
14661461
/* If persistent then set soap_obj from the previous created session (if available) */
14671462
#ifdef SOAP_HAS_SESSION_SUPPORT
@@ -1519,9 +1514,6 @@ PHP_METHOD(SoapServer, handle)
15191514
soap_obj = &tmp_soap;
15201515
}
15211516
}
1522-
soap_zobj = Z_OBJ_P(soap_obj);
1523-
soap_obj_ce = Z_OBJCE_P(soap_obj);
1524-
function_table = &soap_obj_ce->function_table;
15251517
} else {
15261518
if (service->soap_functions.functions_all) {
15271519
function_table = EG(function_table);
@@ -1546,20 +1538,29 @@ PHP_METHOD(SoapServer, handle)
15461538
}
15471539
}
15481540
#endif
1549-
zend_function *header_fn = zend_hash_find_ptr_lc(function_table, Z_STR(h->function_name));
1550-
/* If object has a __call() magic method use it */
1551-
if (header_fn == NULL && soap_obj_ce && soap_obj_ce->__call) {
1552-
header_fn = zend_get_call_trampoline_func(soap_obj_ce, Z_STR(function_name), false);
1553-
}
1554-
if (UNEXPECTED(header_fn == NULL)) {
1555-
if (h->mustUnderstand) {
1556-
soap_server_fault_en("MustUnderstand","Header not understood", NULL, NULL, NULL);
1557-
goto fail;
1541+
1542+
if (soap_obj) {
1543+
/* This is because the object might define a __call() magic method */
1544+
zend_result method_call_result = zend_call_method_if_exists(Z_OBJ_P(soap_obj), Z_STR(h->function_name), &h->retval, h->num_params, h->parameters);
1545+
if (UNEXPECTED(method_call_result == FAILURE)) {
1546+
if (h->mustUnderstand) {
1547+
soap_server_fault_en("MustUnderstand","Header not understood", NULL, NULL, NULL);
1548+
goto fail;
1549+
}
1550+
continue;
15581551
}
1559-
continue;
1552+
} else {
1553+
zend_function *header_fn = zend_hash_find_ptr_lc(function_table, Z_STR(h->function_name));
1554+
if (UNEXPECTED(header_fn == NULL)) {
1555+
if (h->mustUnderstand) {
1556+
soap_server_fault_en("MustUnderstand","Header not understood", NULL, NULL, NULL);
1557+
goto fail;
1558+
}
1559+
continue;
1560+
}
1561+
zend_call_known_function(header_fn, NULL, NULL, &h->retval, h->num_params, h->parameters, NULL);
15601562
}
15611563

1562-
zend_call_known_function(header_fn, soap_zobj, soap_obj_ce, &h->retval, h->num_params, h->parameters, NULL);
15631564
if (Z_TYPE(h->retval) == IS_OBJECT &&
15641565
instanceof_function(Z_OBJCE(h->retval), soap_fault_class_entry)) {
15651566
php_output_discard();
@@ -1575,23 +1576,28 @@ PHP_METHOD(SoapServer, handle)
15751576
}
15761577
}
15771578

1578-
zend_function *fn = zend_hash_find_ptr_lc(function_table, Z_STR(function_name));
1579-
if (UNEXPECTED(fn == NULL)) {
1580-
if (soap_obj_ce && soap_obj_ce->__call) {
1581-
fn = zend_get_call_trampoline_func(soap_obj_ce, Z_STR(function_name), false);
1582-
} else {
1583-
if (soap_obj_ce) {
1584-
zend_throw_error(NULL, "Call to undefined method %s::%s()", ZSTR_VAL(soap_obj_ce->name), Z_STRVAL(function_name));
1585-
} else {
1586-
zend_throw_error(NULL, "Call to undefined function %s()", Z_STRVAL(function_name));
1579+
if (soap_obj) {
1580+
/* This is because the object might define a __call() magic method */
1581+
zend_result method_call_result = zend_call_method_if_exists(Z_OBJ_P(soap_obj), Z_STR(function_name), &retval, num_params, params);
1582+
if (UNEXPECTED(method_call_result == FAILURE)) {
1583+
zend_throw_error(NULL, "Call to undefined method %s::%s()", ZSTR_VAL(Z_OBJCE_P(soap_obj)->name), Z_STRVAL(function_name));
1584+
php_output_discard();
1585+
_soap_server_exception(service, function, ZEND_THIS);
1586+
if (service->type == SOAP_CLASS) {
1587+
zval_ptr_dtor(soap_obj);
15871588
}
1589+
goto fail;
1590+
}
1591+
} else {
1592+
zend_function *fn = zend_hash_find_ptr_lc(function_table, Z_STR(function_name));
1593+
if (UNEXPECTED(fn == NULL)) {
1594+
zend_throw_error(NULL, "Call to undefined function %s()", Z_STRVAL(function_name));
15881595
php_output_discard();
15891596
_soap_server_exception(service, function, ZEND_THIS);
1590-
if (service->type == SOAP_CLASS && soap_obj) {zval_ptr_dtor(soap_obj);}
15911597
goto fail;
15921598
}
1599+
zend_call_known_function(fn, NULL, NULL, &retval, num_params, params, NULL);
15931600
}
1594-
zend_call_known_function(fn, soap_zobj, soap_obj_ce, &retval, num_params, params, NULL);
15951601

15961602
if (service->type == SOAP_CLASS) {
15971603
if (service->soap_class.persistence != SOAP_PERSISTENCE_SESSION) {

0 commit comments

Comments
 (0)