1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
--TEST--
ReflectionClass::newInstanceWithoutConstructor()
--CREDITS--
Sebastian Bergmann <sebastian@php.net>
--FILE--
<?php
class Foo
{
public function __construct()
{
print __METHOD__;
}
}
$class = new ReflectionClass('Foo');
var_dump($class->newInstanceWithoutConstructor());
$class = new ReflectionClass('StdClass');
var_dump($class->newInstanceWithoutConstructor());
$class = new ReflectionClass('DateTime');
var_dump($class->newInstanceWithoutConstructor());
$class = new ReflectionClass('Generator');
try {
var_dump($class->newInstanceWithoutConstructor());
} catch (ReflectionException $e) {
echo $e->getMessage(), "\n";
}
final class Bar extends ArrayObject {
}
$class = new ReflectionClass('Bar');
var_dump($class->newInstanceWithoutConstructor());
?>
--EXPECTF--
object(Foo)#%d (0) {
}
object(stdClass)#%d (0) {
}
object(DateTime)#%d (0) {
}
Class Generator is an internal class marked as final that cannot be instantiated without invoking its constructor
object(Bar)#%d (1) {
["storage":"ArrayObject":private]=>
array(0) {
}
}
|