Skip to content

Commit a7cb572

Browse files
committed
Merge branch 'PHP-5.5'
2 parents 6c8f9c3 + f7b99c4 commit a7cb572

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

ext/reflection/php_reflection.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4192,32 +4192,40 @@ ZEND_METHOD(reflection_class, newInstance)
41924192
{
41934193
zval *retval_ptr = NULL;
41944194
reflection_object *intern;
4195-
zend_class_entry *ce;
4195+
zend_class_entry *ce, *old_scope;
4196+
zend_function *constructor;
41964197

41974198
METHOD_NOTSTATIC(reflection_class_ptr);
41984199
GET_REFLECTION_OBJECT_PTR(ce);
41994200

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+
42004208
/* Run the constructor if there is one */
4201-
if (ce->constructor) {
4209+
if (constructor) {
42024210
zval ***params = NULL;
42034211
int num_args = 0;
42044212
zend_fcall_info fci;
42054213
zend_fcall_info_cache fcc;
42064214

42074215
if (!(ce->constructor->common.fn_flags & ZEND_ACC_PUBLIC)) {
42084216
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();
42104219
}
42114220

42124221
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "*", &params, &num_args) == FAILURE) {
42134222
if (params) {
42144223
efree(params);
42154224
}
4225+
zval_dtor(return_value);
42164226
RETURN_FALSE;
42174227
}
42184228

4219-
object_init_ex(return_value, ce);
4220-
42214229
fci.size = sizeof(fci);
42224230
fci.function_table = EG(function_table);
42234231
fci.function_name = NULL;
@@ -4242,6 +4250,7 @@ ZEND_METHOD(reflection_class, newInstance)
42424250
zval_ptr_dtor(&retval_ptr);
42434251
}
42444252
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invocation of %s's constructor failed", ce->name);
4253+
zval_dtor(return_value);
42454254
RETURN_NULL();
42464255
}
42474256
if (retval_ptr) {
@@ -4250,9 +4259,7 @@ ZEND_METHOD(reflection_class, newInstance)
42504259
if (params) {
42514260
efree(params);
42524261
}
4253-
} else if (!ZEND_NUM_ARGS()) {
4254-
object_init_ex(return_value, ce);
4255-
} else {
4262+
} else if (ZEND_NUM_ARGS()) {
42564263
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);
42574264
}
42584265
}

ext/reflection/tests/bug64007.phpt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
Bug #64007 (There is an ability to create instance of Generator by hand)
3+
--FILE--
4+
<?php
5+
$reflection = new ReflectionClass('Generator');
6+
$generator = $reflection->newInstance();
7+
var_dump($generator);
8+
?>
9+
--EXPECTF--
10+
Catchable fatal error: The "Generator" class is reserved for internal use and cannot be manually instantiated in %sbug64007.php on line %d

0 commit comments

Comments
 (0)