bug29368_3.phpt 613 B

123456789101112131415161718192021222324252627282930313233
  1. --TEST--
  2. Bug #29368.3 (The destructor is called when an exception is thrown from the constructor).
  3. --FILE--
  4. <?php
  5. class Foo {
  6. function __construct() {
  7. echo __METHOD__ . "\n";
  8. }
  9. function __destruct() {
  10. echo __METHOD__ . "\n";
  11. }
  12. }
  13. class Bar {
  14. function __construct() {
  15. echo __METHOD__ . "\n";
  16. throw new Exception;
  17. }
  18. function __destruct() {
  19. echo __METHOD__ . "\n";
  20. }
  21. }
  22. try {
  23. new Foo() + new Bar();
  24. } catch(Exception $exc) {
  25. echo "Caught exception!\n";
  26. }
  27. ?>
  28. --EXPECT--
  29. Foo::__construct
  30. Bar::__construct
  31. Foo::__destruct
  32. Caught exception!