serialization_arrays_003.phpt 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. --TEST--
  2. serialization: arrays with references to an external variable
  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--- 0 refs external:\n";
  29. $ext = 1;
  30. $a = array();
  31. $a[0] = &$ext;
  32. $a[1] = 1;
  33. $a[2] = 1;
  34. check($a);
  35. echo "\n\n--- 1 refs external:\n";
  36. $ext = 1;
  37. $a = array();
  38. $a[0] = 1;
  39. $a[1] = &$ext;
  40. $a[2] = 1;
  41. check($a);
  42. echo "\n\n--- 2 refs external:\n";
  43. $ext = 1;
  44. $a = array();
  45. $a[0] = 1;
  46. $a[1] = 1;
  47. $a[2] = &$ext;
  48. check($a);
  49. echo "\n\n--- 1,2 ref external:\n";
  50. $ext = 1;
  51. $a = array();
  52. $a[0] = &$ext;
  53. $a[1] = &$ext;
  54. $a[2] = 1;
  55. check($a);
  56. echo "\n\n--- 1,2,3 ref external:\n";
  57. $ext = 1;
  58. $a = array();
  59. $a[0] = &$ext;
  60. $a[1] = &$ext;
  61. $a[2] = &$ext;
  62. check($a);
  63. echo "Done";
  64. ?>
  65. --EXPECTF--
  66. --- 0 refs external:
  67. array(3) {
  68. [0]=>
  69. &int(1)
  70. [1]=>
  71. int(1)
  72. [2]=>
  73. int(1)
  74. }
  75. string(30) "a:3:{i:0;i:1;i:1;i:1;i:2;i:1;}"
  76. array(3) {
  77. [0]=>
  78. int(1)
  79. [1]=>
  80. int(1)
  81. [2]=>
  82. int(1)
  83. }
  84. array(3) {
  85. [0]=>
  86. string(10) "b0.changed"
  87. [1]=>
  88. int(1)
  89. [2]=>
  90. int(1)
  91. }
  92. array(3) {
  93. [0]=>
  94. string(10) "b0.changed"
  95. [1]=>
  96. string(10) "b1.changed"
  97. [2]=>
  98. int(1)
  99. }
  100. array(3) {
  101. [0]=>
  102. string(10) "b0.changed"
  103. [1]=>
  104. string(10) "b1.changed"
  105. [2]=>
  106. string(10) "b2.changed"
  107. }
  108. --- 1 refs external:
  109. array(3) {
  110. [0]=>
  111. int(1)
  112. [1]=>
  113. &int(1)
  114. [2]=>
  115. int(1)
  116. }
  117. string(30) "a:3:{i:0;i:1;i:1;i:1;i:2;i:1;}"
  118. array(3) {
  119. [0]=>
  120. int(1)
  121. [1]=>
  122. int(1)
  123. [2]=>
  124. int(1)
  125. }
  126. array(3) {
  127. [0]=>
  128. string(10) "b0.changed"
  129. [1]=>
  130. int(1)
  131. [2]=>
  132. int(1)
  133. }
  134. array(3) {
  135. [0]=>
  136. string(10) "b0.changed"
  137. [1]=>
  138. string(10) "b1.changed"
  139. [2]=>
  140. int(1)
  141. }
  142. array(3) {
  143. [0]=>
  144. string(10) "b0.changed"
  145. [1]=>
  146. string(10) "b1.changed"
  147. [2]=>
  148. string(10) "b2.changed"
  149. }
  150. --- 2 refs external:
  151. array(3) {
  152. [0]=>
  153. int(1)
  154. [1]=>
  155. int(1)
  156. [2]=>
  157. &int(1)
  158. }
  159. string(30) "a:3:{i:0;i:1;i:1;i:1;i:2;i:1;}"
  160. array(3) {
  161. [0]=>
  162. int(1)
  163. [1]=>
  164. int(1)
  165. [2]=>
  166. int(1)
  167. }
  168. array(3) {
  169. [0]=>
  170. string(10) "b0.changed"
  171. [1]=>
  172. int(1)
  173. [2]=>
  174. int(1)
  175. }
  176. array(3) {
  177. [0]=>
  178. string(10) "b0.changed"
  179. [1]=>
  180. string(10) "b1.changed"
  181. [2]=>
  182. int(1)
  183. }
  184. array(3) {
  185. [0]=>
  186. string(10) "b0.changed"
  187. [1]=>
  188. string(10) "b1.changed"
  189. [2]=>
  190. string(10) "b2.changed"
  191. }
  192. --- 1,2 ref external:
  193. array(3) {
  194. [0]=>
  195. &int(1)
  196. [1]=>
  197. &int(1)
  198. [2]=>
  199. int(1)
  200. }
  201. string(30) "a:3:{i:0;i:1;i:1;R:2;i:2;i:1;}"
  202. array(3) {
  203. [0]=>
  204. &int(1)
  205. [1]=>
  206. &int(1)
  207. [2]=>
  208. int(1)
  209. }
  210. array(3) {
  211. [0]=>
  212. &string(10) "b0.changed"
  213. [1]=>
  214. &string(10) "b0.changed"
  215. [2]=>
  216. int(1)
  217. }
  218. array(3) {
  219. [0]=>
  220. &string(10) "b1.changed"
  221. [1]=>
  222. &string(10) "b1.changed"
  223. [2]=>
  224. int(1)
  225. }
  226. array(3) {
  227. [0]=>
  228. &string(10) "b1.changed"
  229. [1]=>
  230. &string(10) "b1.changed"
  231. [2]=>
  232. string(10) "b2.changed"
  233. }
  234. --- 1,2,3 ref external:
  235. array(3) {
  236. [0]=>
  237. &int(1)
  238. [1]=>
  239. &int(1)
  240. [2]=>
  241. &int(1)
  242. }
  243. string(30) "a:3:{i:0;i:1;i:1;R:2;i:2;R:2;}"
  244. array(3) {
  245. [0]=>
  246. &int(1)
  247. [1]=>
  248. &int(1)
  249. [2]=>
  250. &int(1)
  251. }
  252. array(3) {
  253. [0]=>
  254. &string(10) "b0.changed"
  255. [1]=>
  256. &string(10) "b0.changed"
  257. [2]=>
  258. &string(10) "b0.changed"
  259. }
  260. array(3) {
  261. [0]=>
  262. &string(10) "b1.changed"
  263. [1]=>
  264. &string(10) "b1.changed"
  265. [2]=>
  266. &string(10) "b1.changed"
  267. }
  268. array(3) {
  269. [0]=>
  270. &string(10) "b2.changed"
  271. [1]=>
  272. &string(10) "b2.changed"
  273. [2]=>
  274. &string(10) "b2.changed"
  275. }
  276. Done