serialization_arrays_004.phpt 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. --TEST--
  2. serialization: arrays with references to the containing array
  3. --FILE--
  4. <?php
  5. /* Prototype : proto string serialize(mixed variable)
  6. * Description: Returns a string representation of variable (which can later be unserialized)
  7. * Source code: ext/standard/var.c
  8. * Alias to functions:
  9. */
  10. /* Prototype : proto mixed unserialize(string variable_representation)
  11. * Description: Takes a string representation of variable and recreates it
  12. * Source code: ext/standard/var.c
  13. * Alias to functions:
  14. */
  15. function check(&$a) {
  16. var_dump($a);
  17. $ser = serialize($a);
  18. var_dump($ser);
  19. $b = unserialize($ser);
  20. var_dump($b);
  21. $b[0] = "b0.changed";
  22. var_dump($b);
  23. $b[1] = "b1.changed";
  24. var_dump($b);
  25. $b[2] = "b2.changed";
  26. var_dump($b);
  27. }
  28. echo "\n\n--- 1 refs container:\n";
  29. $a = array();
  30. $a[0] = &$a;
  31. $a[1] = 1;
  32. $a[2] = 1;
  33. check($a);
  34. echo "\n\n--- 1,2 ref container:\n";
  35. $a = array();
  36. $a[0] = &$a;
  37. $a[1] = &$a;
  38. $a[2] = 1;
  39. check($a);
  40. echo "\n\n--- 1,2,3 ref container:\n";
  41. $a = array();
  42. $a[0] = &$a;
  43. $a[1] = &$a;
  44. $a[2] = &$a;
  45. check($a);
  46. echo "Done";
  47. ?>
  48. --EXPECTF--
  49. --- 1 refs container:
  50. array(3) {
  51. [0]=>
  52. &array(3) {
  53. [0]=>
  54. *RECURSION*
  55. [1]=>
  56. int(1)
  57. [2]=>
  58. int(1)
  59. }
  60. [1]=>
  61. int(1)
  62. [2]=>
  63. int(1)
  64. }
  65. string(56) "a:3:{i:0;a:3:{i:0;R:2;i:1;i:1;i:2;i:1;}i:1;i:1;i:2;i:1;}"
  66. array(3) {
  67. [0]=>
  68. &array(3) {
  69. [0]=>
  70. *RECURSION*
  71. [1]=>
  72. int(1)
  73. [2]=>
  74. int(1)
  75. }
  76. [1]=>
  77. int(1)
  78. [2]=>
  79. int(1)
  80. }
  81. array(3) {
  82. [0]=>
  83. string(10) "b0.changed"
  84. [1]=>
  85. int(1)
  86. [2]=>
  87. int(1)
  88. }
  89. array(3) {
  90. [0]=>
  91. string(10) "b0.changed"
  92. [1]=>
  93. string(10) "b1.changed"
  94. [2]=>
  95. int(1)
  96. }
  97. array(3) {
  98. [0]=>
  99. string(10) "b0.changed"
  100. [1]=>
  101. string(10) "b1.changed"
  102. [2]=>
  103. string(10) "b2.changed"
  104. }
  105. --- 1,2 ref container:
  106. array(3) {
  107. [0]=>
  108. &array(3) {
  109. [0]=>
  110. *RECURSION*
  111. [1]=>
  112. *RECURSION*
  113. [2]=>
  114. int(1)
  115. }
  116. [1]=>
  117. &array(3) {
  118. [0]=>
  119. *RECURSION*
  120. [1]=>
  121. *RECURSION*
  122. [2]=>
  123. int(1)
  124. }
  125. [2]=>
  126. int(1)
  127. }
  128. string(56) "a:3:{i:0;a:3:{i:0;R:2;i:1;R:2;i:2;i:1;}i:1;R:2;i:2;i:1;}"
  129. array(3) {
  130. [0]=>
  131. &array(3) {
  132. [0]=>
  133. *RECURSION*
  134. [1]=>
  135. *RECURSION*
  136. [2]=>
  137. int(1)
  138. }
  139. [1]=>
  140. &array(3) {
  141. [0]=>
  142. *RECURSION*
  143. [1]=>
  144. *RECURSION*
  145. [2]=>
  146. int(1)
  147. }
  148. [2]=>
  149. int(1)
  150. }
  151. array(3) {
  152. [0]=>
  153. &string(10) "b0.changed"
  154. [1]=>
  155. &string(10) "b0.changed"
  156. [2]=>
  157. int(1)
  158. }
  159. array(3) {
  160. [0]=>
  161. &string(10) "b1.changed"
  162. [1]=>
  163. &string(10) "b1.changed"
  164. [2]=>
  165. int(1)
  166. }
  167. array(3) {
  168. [0]=>
  169. &string(10) "b1.changed"
  170. [1]=>
  171. &string(10) "b1.changed"
  172. [2]=>
  173. string(10) "b2.changed"
  174. }
  175. --- 1,2,3 ref container:
  176. array(3) {
  177. [0]=>
  178. &array(3) {
  179. [0]=>
  180. *RECURSION*
  181. [1]=>
  182. *RECURSION*
  183. [2]=>
  184. *RECURSION*
  185. }
  186. [1]=>
  187. &array(3) {
  188. [0]=>
  189. *RECURSION*
  190. [1]=>
  191. *RECURSION*
  192. [2]=>
  193. *RECURSION*
  194. }
  195. [2]=>
  196. &array(3) {
  197. [0]=>
  198. *RECURSION*
  199. [1]=>
  200. *RECURSION*
  201. [2]=>
  202. *RECURSION*
  203. }
  204. }
  205. string(56) "a:3:{i:0;a:3:{i:0;R:2;i:1;R:2;i:2;R:2;}i:1;R:2;i:2;R:2;}"
  206. array(3) {
  207. [0]=>
  208. &array(3) {
  209. [0]=>
  210. *RECURSION*
  211. [1]=>
  212. *RECURSION*
  213. [2]=>
  214. *RECURSION*
  215. }
  216. [1]=>
  217. &array(3) {
  218. [0]=>
  219. *RECURSION*
  220. [1]=>
  221. *RECURSION*
  222. [2]=>
  223. *RECURSION*
  224. }
  225. [2]=>
  226. &array(3) {
  227. [0]=>
  228. *RECURSION*
  229. [1]=>
  230. *RECURSION*
  231. [2]=>
  232. *RECURSION*
  233. }
  234. }
  235. array(3) {
  236. [0]=>
  237. &string(10) "b0.changed"
  238. [1]=>
  239. &string(10) "b0.changed"
  240. [2]=>
  241. &string(10) "b0.changed"
  242. }
  243. array(3) {
  244. [0]=>
  245. &string(10) "b1.changed"
  246. [1]=>
  247. &string(10) "b1.changed"
  248. [2]=>
  249. &string(10) "b1.changed"
  250. }
  251. array(3) {
  252. [0]=>
  253. &string(10) "b2.changed"
  254. [1]=>
  255. &string(10) "b2.changed"
  256. [2]=>
  257. &string(10) "b2.changed"
  258. }
  259. Done