]> granicus.if.org Git - php/commitdiff
Fix test related to change for #bug64007 and also fix in newInstanceArgs
authorXinchen Hui <laruence@php.net>
Tue, 22 Jan 2013 08:58:40 +0000 (16:58 +0800)
committerXinchen Hui <laruence@php.net>
Tue, 22 Jan 2013 08:58:40 +0000 (16:58 +0800)
ext/pdo/pdo_stmt.c
ext/pdo/tests/pdo_036.phpt
ext/reflection/php_reflection.c
ext/reflection/tests/bug64007.phpt

index a469d09fc2e349b7533212243807e5c927898199..5dc445ff8deb509188549928982edcb4f64f3104 100644 (file)
@@ -2733,6 +2733,7 @@ static union _zend_function *row_get_ctor(zval *object TSRMLS_DC)
        ctor.function_name = "__construct";
        ctor.scope = pdo_row_ce;
        ctor.handler = ZEND_FN(dbstmt_constructor);
+       ctor.fn_flags = ZEND_ACC_PUBLIC;
 
        return (union _zend_function*)&ctor;
 }
index 94006c9e808b6a005cf1e46ab3e6bc272c76d6e5..55c88762ba3ea851b81794c524ebaa93b14eeaf6 100644 (file)
@@ -5,19 +5,19 @@ Testing PDORow and PDOStatement instances with Reflection
 --FILE--
 <?php
 
-$instance = new reflectionclass('pdorow');
+$instance = new reflectionclass('pdostatement');
 $x = $instance->newInstance();
 var_dump($x);
 
-$instance = new reflectionclass('pdostatement');
+$instance = new reflectionclass('pdorow');
 $x = $instance->newInstance();
 var_dump($x);
 
 ?>
 --EXPECTF--
-object(PDORow)#%d (0) {
-}
 object(PDOStatement)#%d (1) {
   [%u|b%"queryString"]=>
   NULL
 }
+
+Fatal error: PDORow::__construct(): You should not create a PDOStatement manually in %spdo_036.php on line %d
index 5c844b8d4dd516df284abd125abc1475dd9914de..15befa2fc725d1ff01936c046303dd70a7763730 100644 (file)
@@ -4212,7 +4212,7 @@ ZEND_METHOD(reflection_class, newInstance)
                zend_fcall_info fci;
                zend_fcall_info_cache fcc;
 
-               if (!(ce->constructor->common.fn_flags & ZEND_ACC_PUBLIC)) {
+               if (!(constructor->common.fn_flags & ZEND_ACC_PUBLIC)) {
                        zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Access to non-public constructor of class %s", ce->name);
                        zval_dtor(return_value);
                        RETURN_NULL();
@@ -4237,7 +4237,7 @@ ZEND_METHOD(reflection_class, newInstance)
                fci.no_separation = 1;
 
                fcc.initialized = 1;
-               fcc.function_handler = ce->constructor;
+               fcc.function_handler = constructor;
                fcc.calling_scope = EG(scope);
                fcc.called_scope = Z_OBJCE_P(return_value);
                fcc.object_ptr = return_value;
@@ -4289,9 +4289,10 @@ ZEND_METHOD(reflection_class, newInstanceArgs)
 {
        zval *retval_ptr = NULL;
        reflection_object *intern;
-       zend_class_entry *ce;
+       zend_class_entry *ce, *old_scope;
        int argc = 0;
        HashTable *args;
+       zend_function *constructor;
 
 
        METHOD_NOTSTATIC(reflection_class_ptr);
@@ -4300,19 +4301,28 @@ ZEND_METHOD(reflection_class, newInstanceArgs)
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|h", &args) == FAILURE) {
                return;
        }
+
        if (ZEND_NUM_ARGS() > 0) {
                argc = args->nNumOfElements;
        }
 
+       object_init_ex(return_value, ce);
+
+       old_scope = EG(scope);
+       EG(scope) = ce;
+       constructor = Z_OBJ_HT_P(return_value)->get_constructor(return_value TSRMLS_CC);
+       EG(scope) = old_scope;
+
        /* Run the constructor if there is one */
-       if (ce->constructor) {
+       if (constructor) {
                zval ***params = NULL;
                zend_fcall_info fci;
                zend_fcall_info_cache fcc;
 
-               if (!(ce->constructor->common.fn_flags & ZEND_ACC_PUBLIC)) {
+               if (!(constructor->common.fn_flags & ZEND_ACC_PUBLIC)) {
                        zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Access to non-public constructor of class %s", ce->name);
-                       return;
+                       zval_dtor(return_value);
+                       RETURN_NULL();
                }
 
                if (argc) {
@@ -4321,8 +4331,6 @@ ZEND_METHOD(reflection_class, newInstanceArgs)
                        params -= argc;
                }
 
-               object_init_ex(return_value, ce);
-
                fci.size = sizeof(fci);
                fci.function_table = EG(function_table);
                fci.function_name = NULL;
@@ -4334,7 +4342,7 @@ ZEND_METHOD(reflection_class, newInstanceArgs)
                fci.no_separation = 1;
 
                fcc.initialized = 1;
-               fcc.function_handler = ce->constructor;
+               fcc.function_handler = constructor;
                fcc.calling_scope = EG(scope);
                fcc.called_scope = Z_OBJCE_P(return_value);
                fcc.object_ptr = return_value;
@@ -4347,6 +4355,7 @@ ZEND_METHOD(reflection_class, newInstanceArgs)
                                zval_ptr_dtor(&retval_ptr);
                        }
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invocation of %s's constructor failed", ce->name);
+                       zval_dtor(return_value);
                        RETURN_NULL();
                }
                if (retval_ptr) {
@@ -4355,9 +4364,7 @@ ZEND_METHOD(reflection_class, newInstanceArgs)
                if (params) {
                        efree(params);
                }
-       } else if (!ZEND_NUM_ARGS() || !argc) {
-               object_init_ex(return_value, ce);
-       } else {
+       } else if (argc) {
                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);
        }
 }
index 34aac7a61b15136786ad263e859ecfd32d85ed4c..32ec6a561078f52aafd2a727000b4488e574c61f 100644 (file)
@@ -3,8 +3,17 @@ Bug #64007 (There is an ability to create instance of Generator by hand)
 --FILE--
 <?php
 $reflection = new ReflectionClass('Generator');
+try {
+    $generator = $reflection->newInstanceWithoutConstructor();
+    var_dump($generator);
+} catch (Exception $e) {
+    var_dump($e->getMessage());
+}
+
 $generator  = $reflection->newInstance();
 var_dump($generator);
 ?>
 --EXPECTF--
+string(97) "Class Generator is an internal class that cannot be instantiated without invoking its constructor"
+
 Catchable fatal error: The "Generator" class is reserved for internal use and cannot be manually instantiated in %sbug64007.php on line %d