xref: /php-src/Zend/tests/bug52614.phpt (revision 7aacc705)
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
55try {
56    $foo->f4()->a = 1;
57} catch (Error $e) {
58    echo $e->getMessage(), "\n";
59}
60var_dump($foo->o1);
61
62$foo->f5()->a = 1;
63var_dump($foo->o2);
64
65$foo->a1[0] = 1;
66$foo->f7($foo->f6()[0]);
67var_dump($foo->a1[0]);
68$foo->f1()[0]++;
69var_dump($foo->a1[0]);
70$foo->f6()[0]++;
71var_dump($foo->a1[0]);
72?>
73--EXPECT--
74NULL
75array(0) {
76}
77array(0) {
78}
79Attempt to assign property "a" on null
80NULL
81object(stdClass)#3 (1) {
82  ["a"]=>
83  int(1)
84}
85int(2)
86int(2)
87int(3)
88