]> granicus.if.org Git - php/commitdiff
ReflectionClass::newInstanceWithoutConstructor() should be allowed to instantiate...
authorFerenc Kovacs <tyrael@php.net>
Wed, 23 Jul 2014 05:45:02 +0000 (07:45 +0200)
committerFerenc Kovacs <tyrael@php.net>
Wed, 30 Jul 2014 08:08:56 +0000 (10:08 +0200)
ext/reflection/php_reflection.c
ext/reflection/tests/ReflectionClass_newInstanceWithoutConstructor.phpt
ext/reflection/tests/bug64007.phpt

index 02a19c0aaabee2af509226d0606143a39bd1c1fe..8ccd5e6f62097b8d47426597edf44db3388e2800 100644 (file)
@@ -4308,8 +4308,8 @@ ZEND_METHOD(reflection_class, newInstanceWithoutConstructor)
        METHOD_NOTSTATIC(reflection_class_ptr);
        GET_REFLECTION_OBJECT_PTR(ce);
 
-       if (ce->create_object != NULL) {
-               zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s is an internal class that cannot be instantiated without invoking its constructor", ce->name);
+       if (ce->create_object != NULL && ce->ce_flags & ZEND_ACC_FINAL_CLASS) {
+               zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s is an internal class with a final __construct thus cannot be instantiated without invoking its constructor", ce->name);
        }
 
        object_init_ex(return_value, ce);
index 1932dbfaf1819febfb802666588ac3abcd52126d..580c5730312c4a608b2582456114a76f62500e80 100644 (file)
@@ -20,13 +20,18 @@ var_dump($class->newInstanceWithoutConstructor());
 
 $class = new ReflectionClass('DateTime');
 var_dump($class->newInstanceWithoutConstructor());
+
+$class = new ReflectionClass('Generator');
+var_dump($class->newInstanceWithoutConstructor());
 --EXPECTF--
 object(Foo)#%d (0) {
 }
 object(stdClass)#%d (0) {
 }
+object(DateTime)#%d (0) {
+}
 
-Fatal error: Uncaught exception 'ReflectionException' with message 'Class DateTime is an internal class that cannot be instantiated without invoking its constructor' in %sReflectionClass_newInstanceWithoutConstructor.php:%d
+Fatal error: Uncaught exception 'ReflectionException' with message 'Class Generator is an internal class with a final __construct thus cannot be instantiated without invoking its constructor' in %sReflectionClass_newInstanceWithoutConstructor.php:%d
 Stack trace:
 #0 %sReflectionClass_newInstanceWithoutConstructor.php(%d): ReflectionClass->newInstanceWithoutConstructor()
 #1 {main}
index 32ec6a561078f52aafd2a727000b4488e574c61f..df8609385efd1a56de258c481acc881bd21701af 100644 (file)
@@ -14,6 +14,6 @@ $generator  = $reflection->newInstance();
 var_dump($generator);
 ?>
 --EXPECTF--
-string(97) "Class Generator is an internal class that cannot be instantiated without invoking its constructor"
+string(%d) "Class Generator is an internal class with a final __construct thus 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