serialization_arrays_002.phpt 6.8 KB

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