serialization_arrays_005.phpt 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. --TEST--
  2. serialization: arrays with references, nested
  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. // Change each element and dump result.
  21. foreach($b as $k=>$v) {
  22. if (is_array($v)){
  23. foreach($b[$k] as $sk=>$sv) {
  24. $b[$k][$sk] = "b$k.$sk.changed";
  25. var_dump($b);
  26. }
  27. } else {
  28. $b[$k] = "b$k.changed";
  29. var_dump($b);
  30. }
  31. }
  32. }
  33. echo "\n\n--- Nested array references 1 element in containing array:\n";
  34. $a = array();
  35. $c = array(1,1,&$a);
  36. $a[0] = &$c[0];
  37. $a[1] = 1;
  38. check($c);
  39. echo "\n\n--- Nested array references 1 element in containing array (slightly different):\n";
  40. $a = array();
  41. $c = array(1,&$a,1);
  42. $a[0] = 1;
  43. $a[1] = &$c[0];
  44. check($c);
  45. echo "\n\n--- Nested array references 2 elements in containing array:\n";
  46. $a = array();
  47. $c = array(1,1,&$a);
  48. $a[0] = &$c[0];
  49. $a[1] = &$c[1];
  50. check($c);
  51. echo "\n\n--- Containing array references 1 element in nested array:\n";
  52. $a = array();
  53. $a[0] = 1;
  54. $a[1] = 1;
  55. $c = array(1,&$a[0],&$a);
  56. check($c);
  57. echo "\n\n--- Containing array references 2 elements in nested array:\n";
  58. $a = array();
  59. $a[0] = 1;
  60. $a[1] = 1;
  61. $c = array(&$a[0],&$a[1],&$a);
  62. check($c);
  63. echo "\n\n--- Nested array references container:\n";
  64. $a = array();
  65. $c = array(1,1,&$a);
  66. $a[0] = 1;
  67. $a[1] = &$c;
  68. check($c);
  69. ?>
  70. --EXPECTF--
  71. --- Nested array references 1 element in containing array:
  72. array(3) {
  73. [0]=>
  74. &int(1)
  75. [1]=>
  76. int(1)
  77. [2]=>
  78. &array(2) {
  79. [0]=>
  80. &int(1)
  81. [1]=>
  82. int(1)
  83. }
  84. }
  85. string(48) "a:3:{i:0;i:1;i:1;i:1;i:2;a:2:{i:0;R:2;i:1;i:1;}}"
  86. array(3) {
  87. [0]=>
  88. &string(10) "b0.changed"
  89. [1]=>
  90. int(1)
  91. [2]=>
  92. array(2) {
  93. [0]=>
  94. &string(10) "b0.changed"
  95. [1]=>
  96. int(1)
  97. }
  98. }
  99. array(3) {
  100. [0]=>
  101. &string(10) "b0.changed"
  102. [1]=>
  103. string(10) "b1.changed"
  104. [2]=>
  105. array(2) {
  106. [0]=>
  107. &string(10) "b0.changed"
  108. [1]=>
  109. int(1)
  110. }
  111. }
  112. array(3) {
  113. [0]=>
  114. &string(12) "b2.0.changed"
  115. [1]=>
  116. string(10) "b1.changed"
  117. [2]=>
  118. array(2) {
  119. [0]=>
  120. &string(12) "b2.0.changed"
  121. [1]=>
  122. int(1)
  123. }
  124. }
  125. array(3) {
  126. [0]=>
  127. &string(12) "b2.0.changed"
  128. [1]=>
  129. string(10) "b1.changed"
  130. [2]=>
  131. array(2) {
  132. [0]=>
  133. &string(12) "b2.0.changed"
  134. [1]=>
  135. string(12) "b2.1.changed"
  136. }
  137. }
  138. --- Nested array references 1 element in containing array (slightly different):
  139. array(3) {
  140. [0]=>
  141. &int(1)
  142. [1]=>
  143. &array(2) {
  144. [0]=>
  145. int(1)
  146. [1]=>
  147. &int(1)
  148. }
  149. [2]=>
  150. int(1)
  151. }
  152. string(48) "a:3:{i:0;i:1;i:1;a:2:{i:0;i:1;i:1;R:2;}i:2;i:1;}"
  153. array(3) {
  154. [0]=>
  155. &string(10) "b0.changed"
  156. [1]=>
  157. array(2) {
  158. [0]=>
  159. int(1)
  160. [1]=>
  161. &string(10) "b0.changed"
  162. }
  163. [2]=>
  164. int(1)
  165. }
  166. array(3) {
  167. [0]=>
  168. &string(10) "b0.changed"
  169. [1]=>
  170. array(2) {
  171. [0]=>
  172. string(12) "b1.0.changed"
  173. [1]=>
  174. &string(10) "b0.changed"
  175. }
  176. [2]=>
  177. int(1)
  178. }
  179. array(3) {
  180. [0]=>
  181. &string(12) "b1.1.changed"
  182. [1]=>
  183. array(2) {
  184. [0]=>
  185. string(12) "b1.0.changed"
  186. [1]=>
  187. &string(12) "b1.1.changed"
  188. }
  189. [2]=>
  190. int(1)
  191. }
  192. array(3) {
  193. [0]=>
  194. &string(12) "b1.1.changed"
  195. [1]=>
  196. array(2) {
  197. [0]=>
  198. string(12) "b1.0.changed"
  199. [1]=>
  200. &string(12) "b1.1.changed"
  201. }
  202. [2]=>
  203. string(10) "b2.changed"
  204. }
  205. --- Nested array references 2 elements in containing array:
  206. array(3) {
  207. [0]=>
  208. &int(1)
  209. [1]=>
  210. &int(1)
  211. [2]=>
  212. &array(2) {
  213. [0]=>
  214. &int(1)
  215. [1]=>
  216. &int(1)
  217. }
  218. }
  219. string(48) "a:3:{i:0;i:1;i:1;i:1;i:2;a:2:{i:0;R:2;i:1;R:3;}}"
  220. array(3) {
  221. [0]=>
  222. &string(10) "b0.changed"
  223. [1]=>
  224. &int(1)
  225. [2]=>
  226. array(2) {
  227. [0]=>
  228. &string(10) "b0.changed"
  229. [1]=>
  230. &int(1)
  231. }
  232. }
  233. array(3) {
  234. [0]=>
  235. &string(10) "b0.changed"
  236. [1]=>
  237. &string(10) "b1.changed"
  238. [2]=>
  239. array(2) {
  240. [0]=>
  241. &string(10) "b0.changed"
  242. [1]=>
  243. &string(10) "b1.changed"
  244. }
  245. }
  246. array(3) {
  247. [0]=>
  248. &string(12) "b2.0.changed"
  249. [1]=>
  250. &string(10) "b1.changed"
  251. [2]=>
  252. array(2) {
  253. [0]=>
  254. &string(12) "b2.0.changed"
  255. [1]=>
  256. &string(10) "b1.changed"
  257. }
  258. }
  259. array(3) {
  260. [0]=>
  261. &string(12) "b2.0.changed"
  262. [1]=>
  263. &string(12) "b2.1.changed"
  264. [2]=>
  265. array(2) {
  266. [0]=>
  267. &string(12) "b2.0.changed"
  268. [1]=>
  269. &string(12) "b2.1.changed"
  270. }
  271. }
  272. --- Containing array references 1 element in nested array:
  273. array(3) {
  274. [0]=>
  275. int(1)
  276. [1]=>
  277. &int(1)
  278. [2]=>
  279. &array(2) {
  280. [0]=>
  281. &int(1)
  282. [1]=>
  283. int(1)
  284. }
  285. }
  286. string(48) "a:3:{i:0;i:1;i:1;i:1;i:2;a:2:{i:0;R:3;i:1;i:1;}}"
  287. array(3) {
  288. [0]=>
  289. string(10) "b0.changed"
  290. [1]=>
  291. &int(1)
  292. [2]=>
  293. array(2) {
  294. [0]=>
  295. &int(1)
  296. [1]=>
  297. int(1)
  298. }
  299. }
  300. array(3) {
  301. [0]=>
  302. string(10) "b0.changed"
  303. [1]=>
  304. &string(10) "b1.changed"
  305. [2]=>
  306. array(2) {
  307. [0]=>
  308. &string(10) "b1.changed"
  309. [1]=>
  310. int(1)
  311. }
  312. }
  313. array(3) {
  314. [0]=>
  315. string(10) "b0.changed"
  316. [1]=>
  317. &string(12) "b2.0.changed"
  318. [2]=>
  319. array(2) {
  320. [0]=>
  321. &string(12) "b2.0.changed"
  322. [1]=>
  323. int(1)
  324. }
  325. }
  326. array(3) {
  327. [0]=>
  328. string(10) "b0.changed"
  329. [1]=>
  330. &string(12) "b2.0.changed"
  331. [2]=>
  332. array(2) {
  333. [0]=>
  334. &string(12) "b2.0.changed"
  335. [1]=>
  336. string(12) "b2.1.changed"
  337. }
  338. }
  339. --- Containing array references 2 elements in nested array:
  340. array(3) {
  341. [0]=>
  342. &int(1)
  343. [1]=>
  344. &int(1)
  345. [2]=>
  346. &array(2) {
  347. [0]=>
  348. &int(1)
  349. [1]=>
  350. &int(1)
  351. }
  352. }
  353. string(48) "a:3:{i:0;i:1;i:1;i:1;i:2;a:2:{i:0;R:2;i:1;R:3;}}"
  354. array(3) {
  355. [0]=>
  356. &string(10) "b0.changed"
  357. [1]=>
  358. &int(1)
  359. [2]=>
  360. array(2) {
  361. [0]=>
  362. &string(10) "b0.changed"
  363. [1]=>
  364. &int(1)
  365. }
  366. }
  367. array(3) {
  368. [0]=>
  369. &string(10) "b0.changed"
  370. [1]=>
  371. &string(10) "b1.changed"
  372. [2]=>
  373. array(2) {
  374. [0]=>
  375. &string(10) "b0.changed"
  376. [1]=>
  377. &string(10) "b1.changed"
  378. }
  379. }
  380. array(3) {
  381. [0]=>
  382. &string(12) "b2.0.changed"
  383. [1]=>
  384. &string(10) "b1.changed"
  385. [2]=>
  386. array(2) {
  387. [0]=>
  388. &string(12) "b2.0.changed"
  389. [1]=>
  390. &string(10) "b1.changed"
  391. }
  392. }
  393. array(3) {
  394. [0]=>
  395. &string(12) "b2.0.changed"
  396. [1]=>
  397. &string(12) "b2.1.changed"
  398. [2]=>
  399. array(2) {
  400. [0]=>
  401. &string(12) "b2.0.changed"
  402. [1]=>
  403. &string(12) "b2.1.changed"
  404. }
  405. }
  406. --- Nested array references container:
  407. array(3) {
  408. [0]=>
  409. int(1)
  410. [1]=>
  411. int(1)
  412. [2]=>
  413. &array(2) {
  414. [0]=>
  415. int(1)
  416. [1]=>
  417. &array(3) {
  418. [0]=>
  419. int(1)
  420. [1]=>
  421. int(1)
  422. [2]=>
  423. *RECURSION*
  424. }
  425. }
  426. }
  427. string(74) "a:3:{i:0;i:1;i:1;i:1;i:2;a:2:{i:0;i:1;i:1;a:3:{i:0;i:1;i:1;i:1;i:2;R:4;}}}"
  428. array(3) {
  429. [0]=>
  430. string(10) "b0.changed"
  431. [1]=>
  432. int(1)
  433. [2]=>
  434. &array(2) {
  435. [0]=>
  436. int(1)
  437. [1]=>
  438. array(3) {
  439. [0]=>
  440. int(1)
  441. [1]=>
  442. int(1)
  443. [2]=>
  444. *RECURSION*
  445. }
  446. }
  447. }
  448. array(3) {
  449. [0]=>
  450. string(10) "b0.changed"
  451. [1]=>
  452. string(10) "b1.changed"
  453. [2]=>
  454. &array(2) {
  455. [0]=>
  456. int(1)
  457. [1]=>
  458. array(3) {
  459. [0]=>
  460. int(1)
  461. [1]=>
  462. int(1)
  463. [2]=>
  464. *RECURSION*
  465. }
  466. }
  467. }
  468. array(3) {
  469. [0]=>
  470. string(10) "b0.changed"
  471. [1]=>
  472. string(10) "b1.changed"
  473. [2]=>
  474. &array(2) {
  475. [0]=>
  476. string(12) "b2.0.changed"
  477. [1]=>
  478. array(3) {
  479. [0]=>
  480. int(1)
  481. [1]=>
  482. int(1)
  483. [2]=>
  484. *RECURSION*
  485. }
  486. }
  487. }
  488. array(3) {
  489. [0]=>
  490. string(10) "b0.changed"
  491. [1]=>
  492. string(10) "b1.changed"
  493. [2]=>
  494. &array(2) {
  495. [0]=>
  496. string(12) "b2.0.changed"
  497. [1]=>
  498. string(12) "b2.1.changed"
  499. }
  500. }