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