xref: /PHP-7.3/Zend/tests/bug52614.phpt (revision 782352c5)
1--TEST--
2Bug #52614 (Memory leak when writing on uninitialized variable returned from method call)
3--FILE--
4<?php
5class foo {
6	public $a1;
7	public $a2 = array();
8	public $a3;
9	public $o1;
10	public $o2;
11
12	public function f1() {
13		return $this->a1;
14	}
15
16	public function f2() {
17		return $this->a2;
18	}
19
20	public function f3() {
21		$this->a3 = array();
22		return $this->a3;
23	}
24
25	public function f4() {
26		return $this->o1;
27	}
28
29	public function f5() {
30		$this->o2 = new stdClass;
31		return $this->o2;
32	}
33
34	public function &f6() {
35		return $this->a1;
36	}
37
38	public function f7(&$x) {
39		$x = 2;
40	}
41
42}
43
44$foo = new foo;
45
46$foo->f1()[0] = 1;
47var_dump($foo->a1);
48
49$foo->f2()[0] = 1;
50var_dump($foo->a2);
51
52$foo->f3()[0] = 1;
53var_dump($foo->a3);
54
55$foo->f4()->a = 1;
56var_dump($foo->o1);
57
58$foo->f5()->a = 1;
59var_dump($foo->o2);
60
61$foo->a1[0] = 1;
62$foo->f7($foo->f6()[0]);
63var_dump($foo->a1[0]);
64$foo->f1()[0]++;
65var_dump($foo->a1[0]);
66$foo->f6()[0]++;
67var_dump($foo->a1[0]);
68--EXPECTF--
69NULL
70array(0) {
71}
72array(0) {
73}
74
75Warning: Creating default object from empty value in %sbug52614.php on line 52
76NULL
77object(stdClass)#%d (1) {
78  ["a"]=>
79  int(1)
80}
81int(2)
82int(2)
83int(3)
84