gc_038.phpt 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. --TEST--
  2. GC 038: Garbage created by compound assignment operators (e.g. +=)
  3. --INI--
  4. zend.enable_gc = 1
  5. --FILE--
  6. <?php
  7. function test_add() {
  8. $x = new stdClass;
  9. $x->x = $x;
  10. try {
  11. $x += 5;
  12. } catch (TypeError $e) { unset($x); }
  13. $n = gc_collect_cycles();
  14. echo "+=\t$n\n";
  15. }
  16. test_add();
  17. function test_sub() {
  18. $x = new stdClass;
  19. $x->x = $x;
  20. try {
  21. $x -= 5;
  22. } catch (TypeError $e) { unset($x); }
  23. $n = gc_collect_cycles();
  24. echo "-=\t$n\n";
  25. }
  26. test_sub();
  27. function test_mul() {
  28. $x = new stdClass;
  29. $x->x = $x;
  30. try {
  31. $x *= 5;
  32. } catch (TypeError $e) { unset($x); }
  33. $n = gc_collect_cycles();
  34. echo "*=\t$n\n";
  35. }
  36. test_mul();
  37. function test_div() {
  38. $x = new stdClass;
  39. $x->x = $x;
  40. try {
  41. $x /= 5;
  42. } catch (TypeError $e) { unset($x); }
  43. $n = gc_collect_cycles();
  44. echo "/=\t$n\n";
  45. }
  46. test_div();
  47. function test_mod() {
  48. $x = new stdClass;
  49. $x->x = $x;
  50. try {
  51. $x %= 5;
  52. } catch (TypeError $e) { unset($x); }
  53. $n = gc_collect_cycles();
  54. echo "%=\t$n\n";
  55. }
  56. test_mod();
  57. function test_sl() {
  58. $x = new stdClass;
  59. $x->x = $x;
  60. try {
  61. $x <<= 5;
  62. } catch (TypeError $e) { unset($x); }
  63. $n = gc_collect_cycles();
  64. echo "<<=\t$n\n";
  65. }
  66. test_sl();
  67. function test_sr() {
  68. $x = new stdClass;
  69. $x->x = $x;
  70. try {
  71. $x >>= 5;
  72. } catch (TypeError $e) { unset($x); }
  73. $n = gc_collect_cycles();
  74. echo ">>=\t$n\n";
  75. }
  76. test_sr();
  77. function test_or() {
  78. $x = new stdClass;
  79. $x->x = $x;
  80. try {
  81. $x |= 5;
  82. } catch (TypeError $e) { unset($x); }
  83. $n = gc_collect_cycles();
  84. echo "|=\t$n\n";
  85. }
  86. test_or();
  87. function test_and() {
  88. $x = new stdClass;
  89. $x->x = $x;
  90. try {
  91. $x &= 5;
  92. } catch (TypeError $e) { unset($x); }
  93. $n = gc_collect_cycles();
  94. echo "&=\t$n\n";
  95. }
  96. test_and();
  97. function test_xor() {
  98. $x = new stdClass;
  99. $x->x = $x;
  100. try {
  101. $x ^= 5;
  102. } catch (TypeError $e) { unset($x); }
  103. $n = gc_collect_cycles();
  104. echo "^=\t$n\n";
  105. }
  106. test_xor();
  107. function test_pow() {
  108. $x = new stdClass;
  109. $x->x = $x;
  110. try {
  111. $x **= 5;
  112. } catch (TypeError $e) { unset($x); }
  113. $n = gc_collect_cycles();
  114. echo "**=\t$n\n";
  115. }
  116. test_pow();
  117. class Y {
  118. function __toString() {
  119. return "y";
  120. }
  121. }
  122. function test_concat() {
  123. $x = new Y;
  124. $x->x= $x;
  125. @$x .= "x";
  126. $n = gc_collect_cycles();
  127. echo ".=\t$n\n";
  128. }
  129. test_concat();
  130. ?>
  131. --EXPECTF--
  132. += 1
  133. -= 1
  134. *= 1
  135. /= 1
  136. %= 1
  137. <<= 1
  138. >>= 1
  139. |= 1
  140. &= 1
  141. ^= 1
  142. **= 1
  143. .= 1