You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

198 lines
3.6 KiB

  1. --TEST--
  2. ZE2 ArrayAccess::offsetSet without return
  3. --SKIPIF--
  4. <?php
  5. if (!class_exists('ArrayAccess')) die('skip ArrayAccess not present');
  6. ?>
  7. --FILE--
  8. <?php
  9. class object implements ArrayAccess {
  10. public $a = array('1st', 1, 2=>'3rd', '4th'=>4);
  11. function offsetExists($index) {
  12. echo __METHOD__ . "($index)\n";
  13. return array_key_exists($index, $this->a);
  14. }
  15. function offsetGet($index) {
  16. echo __METHOD__ . "($index)\n";
  17. return $this->a[$index];
  18. }
  19. function offsetSet($index, $newval) {
  20. echo __METHOD__ . "($index,$newval)\n";
  21. /*return*/ $this->a[$index] = $newval;
  22. }
  23. function offsetUnset($index) {
  24. echo __METHOD__ . "($index)\n";
  25. unset($this->a[$index]);
  26. }
  27. }
  28. $obj = new Object;
  29. var_dump($obj->a);
  30. echo "===EMPTY===\n";
  31. var_dump(empty($obj[0]));
  32. var_dump(empty($obj[1]));
  33. var_dump(empty($obj[2]));
  34. var_dump(empty($obj['4th']));
  35. var_dump(empty($obj['5th']));
  36. var_dump(empty($obj[6]));
  37. echo "===isset===\n";
  38. var_dump(isset($obj[0]));
  39. var_dump(isset($obj[1]));
  40. var_dump(isset($obj[2]));
  41. var_dump(isset($obj['4th']));
  42. var_dump(isset($obj['5th']));
  43. var_dump(isset($obj[6]));
  44. echo "===offsetGet===\n";
  45. var_dump($obj[0]);
  46. var_dump($obj[1]);
  47. var_dump($obj[2]);
  48. var_dump($obj['4th']);
  49. var_dump($obj['5th']);
  50. var_dump($obj[6]);
  51. echo "===offsetSet===\n";
  52. echo "WRITE 1\n";
  53. $obj[1] = 'Changed 1';
  54. var_dump($obj[1]);
  55. echo "WRITE 2\n";
  56. $obj['4th'] = 'Changed 4th';
  57. var_dump($obj['4th']);
  58. echo "WRITE 3\n";
  59. $obj['5th'] = 'Added 5th';
  60. var_dump($obj['5th']);
  61. echo "WRITE 4\n";
  62. $obj[6] = 'Added 6';
  63. var_dump($obj[6]);
  64. var_dump($obj[0]);
  65. var_dump($obj[2]);
  66. $x = $obj[6] = 'changed 6';
  67. var_dump($obj[6]);
  68. var_dump($x);
  69. echo "===unset===\n";
  70. var_dump($obj->a);
  71. unset($obj[2]);
  72. unset($obj['4th']);
  73. unset($obj[7]);
  74. unset($obj['8th']);
  75. var_dump($obj->a);
  76. ?>
  77. ===DONE===
  78. --EXPECTF--
  79. array(4) {
  80. [0]=>
  81. string(3) "1st"
  82. [1]=>
  83. int(1)
  84. [2]=>
  85. string(3) "3rd"
  86. ["4th"]=>
  87. int(4)
  88. }
  89. ===EMPTY===
  90. object::offsetExists(0)
  91. bool(false)
  92. object::offsetExists(1)
  93. bool(false)
  94. object::offsetExists(2)
  95. bool(false)
  96. object::offsetExists(4th)
  97. bool(false)
  98. object::offsetExists(5th)
  99. bool(true)
  100. object::offsetExists(6)
  101. bool(true)
  102. ===isset===
  103. object::offsetExists(0)
  104. bool(true)
  105. object::offsetExists(1)
  106. bool(true)
  107. object::offsetExists(2)
  108. bool(true)
  109. object::offsetExists(4th)
  110. bool(true)
  111. object::offsetExists(5th)
  112. bool(false)
  113. object::offsetExists(6)
  114. bool(false)
  115. ===offsetGet===
  116. object::offsetGet(0)
  117. string(3) "1st"
  118. object::offsetGet(1)
  119. int(1)
  120. object::offsetGet(2)
  121. string(3) "3rd"
  122. object::offsetGet(4th)
  123. int(4)
  124. object::offsetGet(5th)
  125. Notice: Undefined index: 5th in %sarray_access_002.php on line %d
  126. NULL
  127. object::offsetGet(6)
  128. Notice: Undefined offset: 6 in %sarray_access_002.php on line %d
  129. NULL
  130. ===offsetSet===
  131. WRITE 1
  132. object::offsetSet(1,Changed 1)
  133. object::offsetGet(1)
  134. string(9) "Changed 1"
  135. WRITE 2
  136. object::offsetSet(4th,Changed 4th)
  137. object::offsetGet(4th)
  138. string(11) "Changed 4th"
  139. WRITE 3
  140. object::offsetSet(5th,Added 5th)
  141. object::offsetGet(5th)
  142. string(9) "Added 5th"
  143. WRITE 4
  144. object::offsetSet(6,Added 6)
  145. object::offsetGet(6)
  146. string(7) "Added 6"
  147. object::offsetGet(0)
  148. string(3) "1st"
  149. object::offsetGet(2)
  150. string(3) "3rd"
  151. object::offsetSet(6,changed 6)
  152. object::offsetGet(6)
  153. string(9) "changed 6"
  154. string(9) "changed 6"
  155. ===unset===
  156. array(6) {
  157. [0]=>
  158. string(3) "1st"
  159. [1]=>
  160. string(9) "Changed 1"
  161. [2]=>
  162. string(3) "3rd"
  163. ["4th"]=>
  164. string(11) "Changed 4th"
  165. ["5th"]=>
  166. string(9) "Added 5th"
  167. [6]=>
  168. string(9) "changed 6"
  169. }
  170. object::offsetUnset(2)
  171. object::offsetUnset(4th)
  172. object::offsetUnset(7)
  173. object::offsetUnset(8th)
  174. array(4) {
  175. [0]=>
  176. string(3) "1st"
  177. [1]=>
  178. string(9) "Changed 1"
  179. ["5th"]=>
  180. string(9) "Added 5th"
  181. [6]=>
  182. string(9) "changed 6"
  183. }
  184. ===DONE===