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