php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #55490
Patch ReflectionClass_newInstanceWithoutConstructor revision 2011-08-25 13:26 UTC by sebastian@php.net
revision 2011-08-25 09:39 UTC by sebastian@php.net
revision 2011-08-25 09:27 UTC by sebastian@php.net
revision 2011-08-25 09:24 UTC by sebastian@php.net

Patch ReflectionClass_newInstanceWithoutConstructor for Reflection related Bug #55490

Patch version 2011-08-25 09:39 UTC

Return to Bug #55490 | Download this patch
This patch is obsolete

Obsoleted by patches:

This 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 UTC

Developer: sebastian@php.net



  Index: 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,33 @@
 @@ -0,0 +1,28 @@
  +--TEST--
  +ReflectionClass::newInstanceWithoutConstructor()
  +--CREDITS--
  +Sebastian Bergmann <sebastian@php.net>
Line 17 (now 17), was 22 lines, now 17 lines

  +    }
  +}
  +
  +$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 that 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 and 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->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->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);
  +	}
  +
  +	object_init_ex(return_value, ce);
  +}
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Sat Apr 19 22:02:16 2014 UTC