weakrefs_006.phpt 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. --TEST--
  2. WeakReference overwriting existing value
  3. --FILE--
  4. <?php
  5. class HasDtor {
  6. public function __destruct() {
  7. echo "In destruct\n";
  8. global $w, $all;
  9. for ($i = 0; $i < 10; $i++) {
  10. $v = new stdClass();
  11. $all[] = $v;
  12. $w[$v] = $i;
  13. }
  14. }
  15. }
  16. $all = [];
  17. $w = new WeakMap();
  18. $o = new stdClass();
  19. $w[$o] = new HasDtor();
  20. $w[$o] = 123;
  21. var_dump($w);
  22. ?>
  23. --EXPECT--
  24. In destruct
  25. object(WeakMap)#1 (11) {
  26. [0]=>
  27. array(2) {
  28. ["key"]=>
  29. object(stdClass)#2 (0) {
  30. }
  31. ["value"]=>
  32. int(123)
  33. }
  34. [1]=>
  35. array(2) {
  36. ["key"]=>
  37. object(stdClass)#4 (0) {
  38. }
  39. ["value"]=>
  40. int(0)
  41. }
  42. [2]=>
  43. array(2) {
  44. ["key"]=>
  45. object(stdClass)#5 (0) {
  46. }
  47. ["value"]=>
  48. int(1)
  49. }
  50. [3]=>
  51. array(2) {
  52. ["key"]=>
  53. object(stdClass)#6 (0) {
  54. }
  55. ["value"]=>
  56. int(2)
  57. }
  58. [4]=>
  59. array(2) {
  60. ["key"]=>
  61. object(stdClass)#7 (0) {
  62. }
  63. ["value"]=>
  64. int(3)
  65. }
  66. [5]=>
  67. array(2) {
  68. ["key"]=>
  69. object(stdClass)#8 (0) {
  70. }
  71. ["value"]=>
  72. int(4)
  73. }
  74. [6]=>
  75. array(2) {
  76. ["key"]=>
  77. object(stdClass)#9 (0) {
  78. }
  79. ["value"]=>
  80. int(5)
  81. }
  82. [7]=>
  83. array(2) {
  84. ["key"]=>
  85. object(stdClass)#10 (0) {
  86. }
  87. ["value"]=>
  88. int(6)
  89. }
  90. [8]=>
  91. array(2) {
  92. ["key"]=>
  93. object(stdClass)#11 (0) {
  94. }
  95. ["value"]=>
  96. int(7)
  97. }
  98. [9]=>
  99. array(2) {
  100. ["key"]=>
  101. object(stdClass)#12 (0) {
  102. }
  103. ["value"]=>
  104. int(8)
  105. }
  106. [10]=>
  107. array(2) {
  108. ["key"]=>
  109. object(stdClass)#13 (0) {
  110. }
  111. ["value"]=>
  112. int(9)
  113. }
  114. }