serialization_objects_014.phpt 4.7 KB

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