![]() |
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
Patch ReflectionClass_newInstanceWithoutConstructor for Reflection related Bug #55490Patch version 2011-08-25 13:26 UTC Return to Bug #55490 | Download this patchThis patch renders other patches obsolete Obsolete patches: Patch Revisions: 2011-08-25 13:26 UTC | 2011-08-25 09:39 UTC | 2011-08-25 09:27 UTC | 2011-08-25 09:24 UTCDeveloper: sebastian@php.netIndex: ext/reflection/tests/ReflectionClass_newInstanceWithoutConstructor.phpt =================================================================== --- ext/reflection/tests/ReflectionClass_newInstanceWithoutConstructor.phpt (revision 0) +++ ext/reflection/tests/ReflectionClass_newInstanceWithoutConstructor.phpt (revision 0) @@ -0,0 +1,28 @@ @@ -0,0 +1,33 @@ +--TEST-- +ReflectionClass::newInstanceWithoutConstructor() +--CREDITS-- +Sebastian Bergmann <sebastian@php.net> + } +} + +$class = new ReflectionClass('Foo'); +var_dump($class->newInstanceWithoutConstructor()); + +$class = new ReflectionClass('StdClass'); +var_dump($class->newInstanceWithoutConstructor()); + +$class = new ReflectionClass('DateTime'); +var_dump($class->newInstanceWithoutConstructor()); +--EXPECTF-- +object(Foo)#%d (0) { +} +object(stdClass)#%d (0) { +} + +Fatal error: Uncaught exception 'ReflectionException' with message 'Class DateTime is an internal class and cannot be instantiated without invoking its constructor' in %s/tests/ReflectionClass_newInstanceWithoutConstructor.php:%d +Fatal error: Uncaught exception 'ReflectionException' with message 'Class DateTime is an internal class that cannot be instantiated without invoking its constructor' in %s/tests/ReflectionClass_newInstanceWithoutConstructor.php:%d +Stack trace: +#0 %s/ReflectionClass_newInstanceWithoutConstructor.php(%d): ReflectionClass->newInstanceWithoutConstructor() +#1 {main} + thrown in %s/ReflectionClass_newInstanceWithoutConstructor.php on line %d + + METHOD_NOTSTATIC(reflection_class_ptr); + GET_REFLECTION_OBJECT_PTR(ce); + + if (ce->type == ZEND_INTERNAL_CLASS) { + zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s is an internal class and cannot be instantiated without invoking its constructor", ce->name); + 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); + } + + object_init_ex(return_value, ce); +} |
![]() All rights reserved. |
Last updated: Sat Feb 08 11:01:29 2025 UTC |