diff options
author | Ferenc Kovacs <tyrael@php.net> | 2014-07-30 10:23:29 +0200 |
---|---|---|
committer | Ferenc Kovacs <tyrael@php.net> | 2014-07-30 10:23:29 +0200 |
commit | 89b54c2aa5c829cc51c6c2186788e98d9ffe46b6 (patch) | |
tree | 361fe880a7fff905c46570d044ad0aeefedd5439 | |
parent | 43e956a9a1b72dda31f24f1fc9804e19f3391dd4 (diff) | |
parent | d18b16244c0cf3daf806bbad5a459fbd3195f152 (diff) | |
download | php-git-89b54c2aa5c829cc51c6c2186788e98d9ffe46b6.tar.gz |
Merge branch 'newInstanceWithoutConstructor' into PHP-5.6
* newInstanceWithoutConstructor:
update the exception message to better match the actual check
ReflectionClass::newInstanceWithoutConstructor() should be allowed to instantiate every class except those internal classes with a final __construct()
-rw-r--r-- | ext/reflection/php_reflection.c | 4 | ||||
-rw-r--r-- | ext/reflection/tests/ReflectionClass_newInstanceWithoutConstructor.phpt | 7 | ||||
-rw-r--r-- | ext/reflection/tests/bug64007.phpt | 2 |
3 files changed, 9 insertions, 4 deletions
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 02a19c0aaa..8e5fcadef4 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -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 marked as final that cannot be instantiated without invoking its constructor", ce->name); } object_init_ex(return_value, ce); diff --git a/ext/reflection/tests/ReflectionClass_newInstanceWithoutConstructor.phpt b/ext/reflection/tests/ReflectionClass_newInstanceWithoutConstructor.phpt index 1932dbfaf1..dfe3e7f8f7 100644 --- a/ext/reflection/tests/ReflectionClass_newInstanceWithoutConstructor.phpt +++ b/ext/reflection/tests/ReflectionClass_newInstanceWithoutConstructor.phpt @@ -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 marked as final that cannot be instantiated without invoking its constructor' in %sReflectionClass_newInstanceWithoutConstructor.php:%d Stack trace: #0 %sReflectionClass_newInstanceWithoutConstructor.php(%d): ReflectionClass->newInstanceWithoutConstructor() #1 {main} diff --git a/ext/reflection/tests/bug64007.phpt b/ext/reflection/tests/bug64007.phpt index 32ec6a5610..ae3ec50328 100644 --- a/ext/reflection/tests/bug64007.phpt +++ b/ext/reflection/tests/bug64007.phpt @@ -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 marked as final 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 |