bug22510.phpt 2.1 KB

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