ReflectionClass_newInstanceWithoutConstructor.phpt 1.1 KB

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