xref: /php-src/tests/lang/bug22510.phpt (revision 902d6439)
1--TEST--
2Bug #22510 (segfault among complex references)
3--FILE--
4<?php
5
6#[AllowDynamicProperties]
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    public $instance;
35
36    function run1() {
37        print __CLASS__."::".__FUNCTION__."\n";
38        $this->instance = new foo();
39        $this->instance->method1($this);
40        $this->instance->method1($this);
41    }
42
43    function run2() {
44        print __CLASS__."::".__FUNCTION__."\n";
45        $this->instance = new foo();
46        $this->instance->method2($this);
47        $this->instance->method2($this);
48    }
49
50    function run3() {
51        print __CLASS__."::".__FUNCTION__."\n";
52        $this->instance = new foo();
53        $this->instance->method3($this);
54        $this->instance->method3($this);
55    }
56}
57
58function ouch(&$bar) {
59    print __FUNCTION__."\n";
60    @$a = $a;
61    $bar->run1();
62}
63
64function ok1(&$bar) {
65    print __FUNCTION__."\n";
66    $bar->run1();
67}
68
69function ok2(&$bar) {
70    print __FUNCTION__."\n";
71    @$a = $a;
72    $bar->run2();
73}
74
75function ok3(&$bar) {
76    print __FUNCTION__."\n";
77    @$a = $a;
78    $bar->run3();
79}
80
81$foo = new bar();
82$bar =& $foo;
83ok1($bar);
84$bar->instance->finalize();
85print "done!\n";
86ok2($bar);
87$bar->instance->finalize();
88print "done!\n";
89ok3($bar);
90$bar->instance->finalize();
91print "done!\n";
92ouch($bar);
93$bar->instance->finalize();
94print "I'm alive!\n";
95?>
96--EXPECTF--
97ok1
98bar::run1
99foo::method1
100
101Notice: Only variable references should be returned by reference in %s on line %d
102foo::method1
103
104Notice: Only variable references should be returned by reference in %s on line %d
105foo::finalize
106done!
107ok2
108bar::run2
109foo::method2
110foo::method2
111foo::finalize
112done!
113ok3
114bar::run3
115foo::method3
116foo::method3
117foo::finalize
118done!
119ouch
120bar::run1
121foo::method1
122
123Notice: Only variable references should be returned by reference in %s on line %d
124foo::method1
125
126Notice: Only variable references should be returned by reference in %s on line %d
127foo::finalize
128I'm alive!
129