xref: /PHP-7.2/tests/lang/bug22510.phpt (revision 17ccbeec)
1--TEST--
2Bug #22510 (segfault among complex references)
3--INI--
4error_reporting=E_ALL | E_DEPRECATED
5--FILE--
6<?php
7class foo
8{
9	public $list = array();
10
11	function finalize() {
12		print __CLASS__."::".__FUNCTION__."\n";
13		$cl = &$this->list;
14	}
15
16	function &method1() {
17		print __CLASS__."::".__FUNCTION__."\n";
18		return @$this->foo;
19	}
20
21	function &method2() {
22		print __CLASS__."::".__FUNCTION__."\n";
23		return $this->foo;
24	}
25
26	function method3() {
27		print __CLASS__."::".__FUNCTION__."\n";
28		return @$this->foo;
29	}
30}
31
32class bar
33{
34	function run1() {
35		print __CLASS__."::".__FUNCTION__."\n";
36		$this->instance = new foo();
37		$this->instance->method1($this);
38		$this->instance->method1($this);
39	}
40
41	function run2() {
42		print __CLASS__."::".__FUNCTION__."\n";
43		$this->instance = new foo();
44		$this->instance->method2($this);
45		$this->instance->method2($this);
46	}
47
48	function run3() {
49		print __CLASS__."::".__FUNCTION__."\n";
50		$this->instance = new foo();
51		$this->instance->method3($this);
52		$this->instance->method3($this);
53	}
54}
55
56function ouch(&$bar) {
57	print __FUNCTION__."\n";
58	@$a = $a;
59	$bar->run1();
60}
61
62function ok1(&$bar) {
63	print __FUNCTION__."\n";
64	$bar->run1();
65}
66
67function ok2(&$bar) {
68	print __FUNCTION__."\n";
69	@$a = $a;
70	$bar->run2();
71}
72
73function ok3(&$bar) {
74	print __FUNCTION__."\n";
75	@$a = $a;
76	$bar->run3();
77}
78
79$foo = new bar();
80$bar =& $foo;
81ok1($bar);
82$bar->instance->finalize();
83print "done!\n";
84ok2($bar);
85$bar->instance->finalize();
86print "done!\n";
87ok3($bar);
88$bar->instance->finalize();
89print "done!\n";
90ouch($bar);
91$bar->instance->finalize();
92print "I'm alive!\n";
93?>
94--EXPECTF--
95ok1
96bar::run1
97foo::method1
98
99Notice: Only variable references should be returned by reference in %s on line %d
100foo::method1
101
102Notice: Only variable references should be returned by reference in %s on line %d
103foo::finalize
104done!
105ok2
106bar::run2
107foo::method2
108foo::method2
109foo::finalize
110done!
111ok3
112bar::run3
113foo::method3
114foo::method3
115foo::finalize
116done!
117ouch
118bar::run1
119foo::method1
120
121Notice: Only variable references should be returned by reference in %s on line %d
122foo::method1
123
124Notice: Only variable references should be returned by reference in %s on line %d
125foo::finalize
126I'm alive!
127