@@ -4192,32 +4192,40 @@ ZEND_METHOD(reflection_class, newInstance)
4192
4192
{
4193
4193
zval * retval_ptr = NULL ;
4194
4194
reflection_object * intern ;
4195
- zend_class_entry * ce ;
4195
+ zend_class_entry * ce , * old_scope ;
4196
+ zend_function * constructor ;
4196
4197
4197
4198
METHOD_NOTSTATIC (reflection_class_ptr );
4198
4199
GET_REFLECTION_OBJECT_PTR (ce );
4199
4200
4201
+ object_init_ex (return_value , ce );
4202
+
4203
+ old_scope = EG (scope );
4204
+ EG (scope ) = ce ;
4205
+ constructor = Z_OBJ_HT_P (return_value )-> get_constructor (return_value TSRMLS_CC );
4206
+ EG (scope ) = old_scope ;
4207
+
4200
4208
/* Run the constructor if there is one */
4201
- if (ce -> constructor ) {
4209
+ if (constructor ) {
4202
4210
zval * * * params = NULL ;
4203
4211
int num_args = 0 ;
4204
4212
zend_fcall_info fci ;
4205
4213
zend_fcall_info_cache fcc ;
4206
4214
4207
4215
if (!(ce -> constructor -> common .fn_flags & ZEND_ACC_PUBLIC )) {
4208
4216
zend_throw_exception_ex (reflection_exception_ptr , 0 TSRMLS_CC , "Access to non-public constructor of class %s" , ce -> name );
4209
- return ;
4217
+ zval_dtor (return_value );
4218
+ RETURN_NULL ();
4210
4219
}
4211
4220
4212
4221
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "*" , & params , & num_args ) == FAILURE ) {
4213
4222
if (params ) {
4214
4223
efree (params );
4215
4224
}
4225
+ zval_dtor (return_value );
4216
4226
RETURN_FALSE ;
4217
4227
}
4218
4228
4219
- object_init_ex (return_value , ce );
4220
-
4221
4229
fci .size = sizeof (fci );
4222
4230
fci .function_table = EG (function_table );
4223
4231
fci .function_name = NULL ;
@@ -4242,6 +4250,7 @@ ZEND_METHOD(reflection_class, newInstance)
4242
4250
zval_ptr_dtor (& retval_ptr );
4243
4251
}
4244
4252
php_error_docref (NULL TSRMLS_CC , E_WARNING , "Invocation of %s's constructor failed" , ce -> name );
4253
+ zval_dtor (return_value );
4245
4254
RETURN_NULL ();
4246
4255
}
4247
4256
if (retval_ptr ) {
@@ -4250,9 +4259,7 @@ ZEND_METHOD(reflection_class, newInstance)
4250
4259
if (params ) {
4251
4260
efree (params );
4252
4261
}
4253
- } else if (!ZEND_NUM_ARGS ()) {
4254
- object_init_ex (return_value , ce );
4255
- } else {
4262
+ } else if (ZEND_NUM_ARGS ()) {
4256
4263
zend_throw_exception_ex (reflection_exception_ptr , 0 TSRMLS_CC , "Class %s does not have a constructor, so you cannot pass any constructor arguments" , ce -> name );
4257
4264
}
4258
4265
}
0 commit comments