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.

311 lines
5.5 KiB

  1. --TEST--
  2. ZE2 ArrayAccess
  3. --FILE--
  4. <?php
  5. class object implements ArrayAccess {
  6. public $a = array('1st', 1, 2=>'3rd', '4th'=>4);
  7. function offsetExists($index) {
  8. echo __METHOD__ . "($index)\n";
  9. return array_key_exists($index, $this->a);
  10. }
  11. function offsetGet($index) {
  12. echo __METHOD__ . "($index)\n";
  13. return $this->a[$index];
  14. }
  15. function offsetSet($index, $newval) {
  16. echo __METHOD__ . "($index,$newval)\n";
  17. return $this->a[$index] = $newval;
  18. }
  19. function offsetUnset($index) {
  20. echo __METHOD__ . "($index)\n";
  21. unset($this->a[$index]);
  22. }
  23. }
  24. $obj = new Object;
  25. var_dump($obj->a);
  26. echo "===EMPTY===\n";
  27. var_dump(empty($obj[0]));
  28. var_dump(empty($obj[1]));
  29. var_dump(empty($obj[2]));
  30. var_dump(empty($obj['4th']));
  31. var_dump(empty($obj['5th']));
  32. var_dump(empty($obj[6]));
  33. echo "===isset===\n";
  34. var_dump(isset($obj[0]));
  35. var_dump(isset($obj[1]));
  36. var_dump(isset($obj[2]));
  37. var_dump(isset($obj['4th']));
  38. var_dump(isset($obj['5th']));
  39. var_dump(isset($obj[6]));
  40. echo "===offsetGet===\n";
  41. var_dump($obj[0]);
  42. var_dump($obj[1]);
  43. var_dump($obj[2]);
  44. var_dump($obj['4th']);
  45. var_dump($obj['5th']);
  46. var_dump($obj[6]);
  47. echo "===offsetSet===\n";
  48. echo "WRITE 1\n";
  49. $obj[1] = 'Changed 1';
  50. var_dump($obj[1]);
  51. echo "WRITE 2\n";
  52. $obj['4th'] = 'Changed 4th';
  53. var_dump($obj['4th']);
  54. echo "WRITE 3\n";
  55. $obj['5th'] = 'Added 5th';
  56. var_dump($obj['5th']);
  57. echo "WRITE 4\n";
  58. $obj[6] = 'Added 6';
  59. var_dump($obj[6]);
  60. var_dump($obj[0]);
  61. var_dump($obj[2]);
  62. $x = $obj[6] = 'changed 6';
  63. var_dump($obj[6]);
  64. var_dump($x);
  65. echo "===unset===\n";
  66. var_dump($obj->a);
  67. unset($obj[2]);
  68. unset($obj['4th']);
  69. unset($obj[7]);
  70. unset($obj['8th']);
  71. var_dump($obj->a);
  72. ?>
  73. ===DONE===
  74. --EXPECTF--
  75. array(4) {
  76. [0]=>
  77. string(3) "1st"
  78. [1]=>
  79. int(1)
  80. [2]=>
  81. string(3) "3rd"
  82. ["4th"]=>
  83. int(4)
  84. }
  85. ===EMPTY===
  86. object::offsetExists(0)
  87. object::offsetGet(0)
  88. bool(false)
  89. object::offsetExists(1)
  90. object::offsetGet(1)
  91. bool(false)
  92. object::offsetExists(2)
  93. object::offsetGet(2)
  94. bool(false)
  95. object::offsetExists(4th)
  96. object::offsetGet(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_001.php on line %d
  126. NULL
  127. object::offsetGet(6)
  128. Notice: Undefined offset: 6 in %sarray_access_001.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===
  185. --UEXPECTF--
  186. array(4) {
  187. [0]=>
  188. unicode(3) "1st"
  189. [1]=>
  190. int(1)
  191. [2]=>
  192. unicode(3) "3rd"
  193. [u"4th"]=>
  194. int(4)
  195. }
  196. ===EMPTY===
  197. object::offsetExists(0)
  198. object::offsetGet(0)
  199. bool(false)
  200. object::offsetExists(1)
  201. object::offsetGet(1)
  202. bool(false)
  203. object::offsetExists(2)
  204. object::offsetGet(2)
  205. bool(false)
  206. object::offsetExists(4th)
  207. object::offsetGet(4th)
  208. bool(false)
  209. object::offsetExists(5th)
  210. bool(true)
  211. object::offsetExists(6)
  212. bool(true)
  213. ===isset===
  214. object::offsetExists(0)
  215. bool(true)
  216. object::offsetExists(1)
  217. bool(true)
  218. object::offsetExists(2)
  219. bool(true)
  220. object::offsetExists(4th)
  221. bool(true)
  222. object::offsetExists(5th)
  223. bool(false)
  224. object::offsetExists(6)
  225. bool(false)
  226. ===offsetGet===
  227. object::offsetGet(0)
  228. unicode(3) "1st"
  229. object::offsetGet(1)
  230. int(1)
  231. object::offsetGet(2)
  232. unicode(3) "3rd"
  233. object::offsetGet(4th)
  234. int(4)
  235. object::offsetGet(5th)
  236. Notice: Undefined index: 5th in %sarray_access_001.php on line %d
  237. NULL
  238. object::offsetGet(6)
  239. Notice: Undefined offset: 6 in %sarray_access_001.php on line %d
  240. NULL
  241. ===offsetSet===
  242. WRITE 1
  243. object::offsetSet(1,Changed 1)
  244. object::offsetGet(1)
  245. unicode(9) "Changed 1"
  246. WRITE 2
  247. object::offsetSet(4th,Changed 4th)
  248. object::offsetGet(4th)
  249. unicode(11) "Changed 4th"
  250. WRITE 3
  251. object::offsetSet(5th,Added 5th)
  252. object::offsetGet(5th)
  253. unicode(9) "Added 5th"
  254. WRITE 4
  255. object::offsetSet(6,Added 6)
  256. object::offsetGet(6)
  257. unicode(7) "Added 6"
  258. object::offsetGet(0)
  259. unicode(3) "1st"
  260. object::offsetGet(2)
  261. unicode(3) "3rd"
  262. object::offsetSet(6,changed 6)
  263. object::offsetGet(6)
  264. unicode(9) "changed 6"
  265. unicode(9) "changed 6"
  266. ===unset===
  267. array(6) {
  268. [0]=>
  269. unicode(3) "1st"
  270. [1]=>
  271. unicode(9) "Changed 1"
  272. [2]=>
  273. unicode(3) "3rd"
  274. [u"4th"]=>
  275. unicode(11) "Changed 4th"
  276. [u"5th"]=>
  277. unicode(9) "Added 5th"
  278. [6]=>
  279. unicode(9) "changed 6"
  280. }
  281. object::offsetUnset(2)
  282. object::offsetUnset(4th)
  283. object::offsetUnset(7)
  284. object::offsetUnset(8th)
  285. array(4) {
  286. [0]=>
  287. unicode(3) "1st"
  288. [1]=>
  289. unicode(9) "Changed 1"
  290. [u"5th"]=>
  291. unicode(9) "Added 5th"
  292. [6]=>
  293. unicode(9) "changed 6"
  294. }
  295. ===DONE===