xref: /PHP-7.2/tests/classes/ctor_failure.phpt (revision 17ccbeec)
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===DONE===
30--EXPECT--
31Test::__construct(Hello)
32Caught Exception(Hello)
33===DONE===
34