xref: /PHP-5.3/tests/lang/bug22510.phpt (revision d3e50265)
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$bar = &new bar();
80ok1($bar);
81$bar->instance->finalize();
82print "done!\n";
83ok2($bar);
84$bar->instance->finalize();
85print "done!\n";
86ok3($bar);
87$bar->instance->finalize();
88print "done!\n";
89ouch($bar);
90$bar->instance->finalize();
91print "I'm alive!\n";
92?>
93--EXPECTF--
94Deprecated: Assigning the return value of new by reference is deprecated in %s on line %d
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