xref: /PHP-8.0/tests/classes/ctor_failure.phpt (revision a555cc0b)
1--TEST--
2ZE2 Do not call destructors if constructor fails
3--FILE--
4<?php
5
6class Test
7{
8    function __construct($msg) {
9        echo __METHOD__ . "($msg)\n";
10        throw new Exception($msg);
11    }
12
13    function __destruct() {
14        echo __METHOD__ . "\n";
15    }
16}
17
18try
19{
20    $o = new Test('Hello');
21    unset($o);
22}
23catch (Exception $e)
24{
25    echo 'Caught ' . get_class($e) . '(' . $e->getMessage() . ")\n";
26}
27
28?>
29--EXPECT--
30Test::__construct(Hello)
31Caught Exception(Hello)
32