1--TEST-- 2ReflectionClass::newInstanceWithoutConstructor() 3--CREDITS-- 4Sebastian Bergmann <sebastian@php.net> 5--FILE-- 6<?php 7class Foo 8{ 9 public function __construct() 10 { 11 print __METHOD__; 12 } 13} 14 15$class = new ReflectionClass('Foo'); 16var_dump($class->newInstanceWithoutConstructor()); 17 18$class = new ReflectionClass('StdClass'); 19var_dump($class->newInstanceWithoutConstructor()); 20 21$class = new ReflectionClass('DateTime'); 22var_dump($class->newInstanceWithoutConstructor()); 23--EXPECTF-- 24object(Foo)#%d (0) { 25} 26object(stdClass)#%d (0) { 27} 28 29Fatal 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 30Stack trace: 31#0 %sReflectionClass_newInstanceWithoutConstructor.php(%d): ReflectionClass->newInstanceWithoutConstructor() 32#1 {main} 33 thrown in %sReflectionClass_newInstanceWithoutConstructor.php on line %d 34