bug38220.phpt 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. --TEST--
  2. Bug #38220 (Crash on some object operations)
  3. --FILE--
  4. <?php
  5. class drv {
  6. public $obj;
  7. function func1() {
  8. echo "func1(): {$this->obj->i}\n";
  9. }
  10. function close() {
  11. echo "close(): {$this->obj->i}\n";
  12. }
  13. }
  14. class A {
  15. public $i;
  16. function __construct($i) {
  17. $this->i = $i;
  18. }
  19. function __call($method, $args) {
  20. $drv = myserv::drv();
  21. $drv->obj = $this;
  22. echo "before call $method\n";
  23. print_r($this);
  24. call_user_func_array(array($drv, $method), $args);
  25. echo "after call $method\n";
  26. // Uncomment this line to work without crash
  27. // $drv->obj = null;
  28. }
  29. function __destruct() {
  30. echo "A::__destruct()\n";
  31. $this->close();
  32. }
  33. }
  34. class myserv {
  35. private static $drv = null;
  36. static function drv() {
  37. if (is_null(self::$drv))
  38. self::$drv = new drv;
  39. return self::$drv;
  40. }
  41. }
  42. $obj1 = new A(1);
  43. $obj1->func1();
  44. $obj2 = new A(2);
  45. unset($obj1);
  46. $obj2->func1();
  47. ?>
  48. --EXPECT--
  49. before call func1
  50. A Object
  51. (
  52. [i] => 1
  53. )
  54. func1(): 1
  55. after call func1
  56. A::__destruct()
  57. before call close
  58. A Object
  59. (
  60. [i] => 1
  61. )
  62. close(): 1
  63. after call close
  64. before call func1
  65. A Object
  66. (
  67. [i] => 2
  68. )
  69. func1(): 1
  70. after call func1
  71. A::__destruct()
  72. before call close
  73. A Object
  74. (
  75. [i] => 2
  76. )
  77. close(): 2
  78. after call close