xref: /PHP-7.3/Zend/tests/try/catch_004.phpt (revision 782352c5)
1--TEST--
2Catching an exception in a constructor inside a static method
3--FILE--
4<?php
5
6class MyObject
7{
8	function fail()
9	{
10		throw new Exception();
11	}
12
13	function __construct()
14	{
15		self::fail();
16		echo __METHOD__ . "() Must not be reached\n";
17	}
18
19	function __destruct()
20	{
21		echo __METHOD__ . "() Must not be called\n";
22	}
23
24	static function test()
25	{
26		try
27		{
28			new MyObject();
29		}
30		catch(Exception $e)
31		{
32			echo "Caught\n";
33		}
34	}
35}
36
37MyObject::test();
38
39?>
40===DONE===
41--EXPECT--
42Caught
43===DONE===
44