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