bug22510.phpt 2.3 KB

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