xref: /PHP-8.1/Zend/tests/bug30162.phpt (revision 36935e42)
1--TEST--
2Bug #30162 (Catching exception in constructor couses lose of $this)
3--FILE--
4<?php
5class FIIFO {
6
7    public function __construct() {
8        $this->x = "x";
9        throw new Exception;
10    }
11
12}
13
14class hariCow extends FIIFO {
15
16    public function __construct() {
17        try {
18            parent::__construct();
19        } catch(Exception $e) {
20        }
21        $this->y = "y";
22        try {
23            $this->z = new FIIFO;
24        } catch(Exception $e) {
25        }
26    }
27
28    public function __toString() {
29        return "Rusticus in asino sedet.";
30    }
31
32}
33
34try {
35    $db = new FIIFO();
36} catch(Exception $e) {
37}
38var_dump($db);
39
40$db = new hariCow;
41
42var_dump($db);
43?>
44--EXPECTF--
45Warning: Undefined variable $db in %s on line %d
46NULL
47object(hariCow)#%d (2) {
48  ["x"]=>
49  string(1) "x"
50  ["y"]=>
51  string(1) "y"
52}
53