From: Antony Dovgal Date: Mon, 14 Aug 2006 15:00:04 +0000 (+0000) Subject: fix #38450 (constructor is not called for classes used in userspace stream wrappers) X-Git-Tag: RELEASE_1_0_0RC1~1966 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a4a561dc72a09bedb9e617423a94a7f470813da8;p=php fix #38450 (constructor is not called for classes used in userspace stream wrappers) --- diff --git a/main/streams/userspace.c b/main/streams/userspace.c index 5091dfdbe9..475b680593 100644 --- a/main/streams/userspace.c +++ b/main/streams/userspace.c @@ -231,6 +231,40 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, char *filena object_init_ex(us->object, uwrap->ce); ZVAL_REFCOUNT(us->object) = 1; PZVAL_IS_REF(us->object) = 1; + + if (uwrap->ce->constructor) { + zend_fcall_info fci; + zend_fcall_info_cache fcc; + zval *retval_ptr; + + fci.size = sizeof(fci); + fci.function_table = &uwrap->ce->function_table; + fci.function_name = NULL; + fci.symbol_table = NULL; + fci.object_pp = &us->object; + fci.retval_ptr_ptr = &retval_ptr; + fci.param_count = 0; + fci.params = NULL; + fci.no_separation = 1; + + fcc.initialized = 1; + fcc.function_handler = uwrap->ce->constructor; + fcc.calling_scope = EG(scope); + fcc.object_pp = &us->object; + + if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not execute %s::%s()", uwrap->ce->name, uwrap->ce->constructor->common.function_name); + zval_dtor(us->object); + FREE_ZVAL(us->object); + efree(us); + FG(user_stream_current_filename) = NULL; + return NULL; + } else { + if (retval_ptr) { + zval_ptr_dtor(&retval_ptr); + } + } + } if (context) { MAKE_STD_ZVAL(zcontext);