xref: /PHP-8.2/Zend/tests/bug52041.phpt (revision c48b745f)
1--TEST--
2Bug #52041 (Memory leak when writing on uninitialized variable returned from function)
3--FILE--
4<?php
5function foo() {
6    return $x;
7}
8
9try {
10    foo()->a = 1;
11} catch (Error $e) {
12    echo $e->getMessage(), "\n";
13}
14try {
15    foo()->a->b = 2;
16} catch (Error $e) {
17    echo $e->getMessage(), "\n";
18}
19try {
20    foo()->a++;
21} catch (Error $e) {
22    echo $e->getMessage(), "\n";
23}
24try {
25    foo()->a->b++;
26} catch (Error $e) {
27    echo $e->getMessage(), "\n";
28}
29try {
30    foo()->a += 2;
31} catch (Error $e) {
32    echo $e->getMessage(), "\n";
33}
34try {
35    foo()->a->b += 2;
36} catch (Error $e) {
37    echo $e->getMessage(), "\n";
38}
39
40foo()[0] = 1;
41foo()[0][0] = 2;
42foo()[0]++;
43foo()[0][0]++;
44foo()[0] += 2;
45foo()[0][0] += 2;
46
47var_dump(foo());
48?>
49--EXPECTF--
50Warning: Undefined variable $x in %s on line %d
51Attempt to assign property "a" on null
52
53Warning: Undefined variable $x in %s on line %d
54Attempt to modify property "a" on null
55
56Warning: Undefined variable $x in %s on line %d
57Attempt to increment/decrement property "a" on null
58
59Warning: Undefined variable $x in %s on line %d
60Attempt to modify property "a" on null
61
62Warning: Undefined variable $x in %s on line %d
63Attempt to assign property "a" on null
64
65Warning: Undefined variable $x in %s on line %d
66Attempt to modify property "a" on null
67
68Warning: Undefined variable $x in %s on line %d
69
70Warning: Undefined variable $x in %s on line %d
71
72Warning: Undefined variable $x in %s on line %d
73
74Warning: Undefined array key 0 in %s on line %d
75
76Warning: Undefined variable $x in %s on line %d
77
78Warning: Undefined array key 0 in %s on line %d
79
80Warning: Undefined array key 0 in %s on line %d
81
82Warning: Undefined variable $x in %s on line %d
83
84Warning: Undefined array key 0 in %s on line %d
85
86Warning: Undefined variable $x in %s on line %d
87
88Warning: Undefined array key 0 in %s on line %d
89
90Warning: Undefined array key 0 in %s on line %d
91
92Warning: Undefined variable $x in %s on line %d
93NULL
94