Fix memoization of functions called with keyset arguments
[hiphop-php.git] / hphp / test / quick / exception_destructor_1.php
blob1222681ac737e950ff5d6948ced4dfd6d82d05c0
1 <?php
2 // Copyright 2004-2015 Facebook. All Rights Reserved.
4 // Test behavior around exceptions leaking out of destructors.
5 // Specifically, fatals vs. user exceptions.
7 class Ex1 extends Exception {
10 class Ex2 extends Exception {
13 class ThrowDestruct1 {
14 public function __destruct() {
15 printf("In ThrowDestruct1::__destruct()\n");
16 throw new Ex1('Exception leaked out of ThrowDestruct1::__destruct()');
20 class ThrowDestruct2 {
21 public function __destruct() {
22 printf("In ThrowDestruct2::__destruct()\n");
23 throw new Ex2('Exception leaked out of ThrowDestruct2::__destruct()');
27 class ExitDestruct {
28 public function __destruct() {
29 printf("In ExitDestruct::__destruct()\n");
30 exit();
34 function bar() {
35 $td2 = new ThrowDestruct2;
37 // The exit() in ExitDestruct::__destruct() should prevent the destructor
38 // for $td2 from running, as well as any up-stack destructors.
39 $ed = new ExitDestruct;
42 function foo() {
43 $td1 = new ThrowDestruct1;
44 printf("Calling bar()\n");
45 bar();
46 printf("After bar()\n");
49 function printPreviousExceptions($e) {
50 $i = 0;
52 while ($e = $e->getPrevious()) {
53 printf("\tPrevious #%d: %s\n", ++$i, $e->getMessage());
57 function main() {
58 printf("main() starting\n");
60 try {
61 printf("Calling foo()\n");
62 foo();
63 printf("After foo()\n");
65 catch (Exception $e) {
66 printf("Caught %s in main()\n", $e->getMessage());
67 printPreviousExceptions($e);
70 printf("main() ending\n");
73 printf("Calling main()\n");
74 main();
75 printf("Returned from main(), exiting\n");