1
0
mirror of https://github.com/php/php-src.git synced 2026-04-26 17:38:14 +02:00

Simplify constructor invocation in ext/soap

Use ce->constructor and zend_call_known_instance_method. There
is no need to look up a method with the same name as the class
anymore.
This commit is contained in:
Nikita Popov
2021-08-19 16:04:43 +02:00
parent 7d4f2f5392
commit e6d4b3077d
+4 -38
View File
@@ -1394,50 +1394,16 @@ PHP_METHOD(SoapServer, handle)
object_init_ex(&tmp_soap, service->soap_class.ce);
/* Call constructor */
if (zend_hash_str_exists(&Z_OBJCE(tmp_soap)->function_table, ZEND_CONSTRUCTOR_FUNC_NAME, sizeof(ZEND_CONSTRUCTOR_FUNC_NAME)-1)) {
zval c_ret, constructor;
ZVAL_STRING(&constructor, ZEND_CONSTRUCTOR_FUNC_NAME);
if (call_user_function(NULL, &tmp_soap, &constructor, &c_ret, service->soap_class.argc, service->soap_class.argv) == FAILURE) {
php_error_docref(NULL, E_ERROR, "Error calling constructor");
}
if (service->soap_class.ce->constructor) {
zend_call_known_instance_method(
service->soap_class.ce->constructor, Z_OBJ(tmp_soap), NULL,
service->soap_class.argc, service->soap_class.argv);
if (EG(exception)) {
php_output_discard();
_soap_server_exception(service, function, ZEND_THIS);
zval_ptr_dtor_str(&constructor);
zval_ptr_dtor(&c_ret);
zval_ptr_dtor(&tmp_soap);
goto fail;
}
zval_ptr_dtor_str(&constructor);
zval_ptr_dtor(&c_ret);
} else {
int class_name_len = ZSTR_LEN(service->soap_class.ce->name);
char *class_name = emalloc(class_name_len+1);
memcpy(class_name, ZSTR_VAL(service->soap_class.ce->name), class_name_len+1);
if (zend_hash_str_exists(&Z_OBJCE(tmp_soap)->function_table, php_strtolower(class_name, class_name_len), class_name_len)) {
zval c_ret, constructor;
ZVAL_STR_COPY(&constructor, service->soap_class.ce->name);
if (call_user_function(NULL, &tmp_soap, &constructor, &c_ret, service->soap_class.argc, service->soap_class.argv) == FAILURE) {
php_error_docref(NULL, E_ERROR, "Error calling constructor");
}
if (EG(exception)) {
php_output_discard();
_soap_server_exception(service, function, ZEND_THIS);
zval_ptr_dtor_str(&constructor);
zval_ptr_dtor(&c_ret);
efree(class_name);
zval_ptr_dtor(&tmp_soap);
goto fail;
}
zval_ptr_dtor_str(&constructor);
zval_ptr_dtor(&c_ret);
}
efree(class_name);
}
#if defined(HAVE_PHP_SESSION) && !defined(COMPILE_DL_SESSION)
/* If session then update session hash with new object */