serialization_objects_002.phpt 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. --TEST--
  2. Test serialize() & unserialize() functions: objects (variations)
  3. --INI--
  4. serialize_precision=100
  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. echo "\n--- Testing Variations in objects ---\n";
  18. class members
  19. {
  20. private $var_private = 10;
  21. protected $var_protected = "string";
  22. public $var_public = array(-100.123, "string", TRUE);
  23. }
  24. class nomembers { }
  25. class C {
  26. var $a, $b, $c, $d, $e, $f, $g, $h;
  27. function __construct() {
  28. $this->a = 10;
  29. $this->b = "string";
  30. $this->c = TRUE;
  31. $this->d = -2.34444;
  32. $this->e = array(1, 2.22, "string", TRUE, array(),
  33. new members(), null);
  34. $this->f = new nomembers();
  35. $this->g = $GLOBALS['file_handle'];
  36. $this->h = NULL;
  37. }
  38. }
  39. class D extends C {
  40. function __construct( $w, $x, $y, $z ) {
  41. $this->a = $w;
  42. $this->b = $x;
  43. $this->c = $y;
  44. $this->d = $z;
  45. }
  46. }
  47. $variation_obj_arr = array(
  48. new C(),
  49. new D( 1, 2, 3333, 444444 ),
  50. new D( .5, 0.005, -1.345, 10.005e5 ),
  51. new D( TRUE, true, FALSE, false ),
  52. new D( "a", 'a', "string", 'string' ),
  53. new D( array(),
  54. array(1, 2.222, TRUE, FALSE, "string"),
  55. array(new nomembers(), $file_handle, NULL, ""),
  56. array(array(1,2,3,array()))
  57. ),
  58. new D( NULL, null, "", "\0" ),
  59. new D( new members, new nomembers, $file_handle, NULL),
  60. );
  61. /* Testing serialization on all the objects through loop */
  62. foreach( $variation_obj_arr as $object) {
  63. echo "After Serialization => ";
  64. $serialize_data = serialize( $object );
  65. var_dump( $serialize_data );
  66. echo "After Unserialization => ";
  67. $unserialize_data = unserialize( $serialize_data );
  68. var_dump( $unserialize_data );
  69. }
  70. echo "\nDone";
  71. ?>
  72. --EXPECTF--
  73. --- Testing Variations in objects ---
  74. Notice: Undefined index: file_handle in %s on line 34
  75. Notice: Undefined variable: file_handle in %s on line 56
  76. Notice: Undefined variable: file_handle in %s on line 60
  77. After Serialization => string(493) "O:1:"C":8:{s:1:"a";i:10;s:1:"b";s:6:"string";s:1:"c";b:1;s:1:"d";d:-2.344440000000000079438677857979200780391693115234375;s:1:"e";a:7:{i:0;i:1;i:1;d:2.220000000000000195399252334027551114559173583984375;i:2;s:6:"string";i:3;b:1;i:4;a:0:{}i:5;O:7:"members":3:{s:20:"�members�var_private";i:10;s:16:"�*�var_protected";s:6:"string";s:10:"var_public";a:3:{i:0;d:-100.1230000000000046611603465862572193145751953125;i:1;s:6:"string";i:2;b:1;}}i:6;N;}s:1:"f";O:9:"nomembers":0:{}s:1:"g";N;s:1:"h";N;}"
  78. After Unserialization => object(C)#%d (8) {
  79. ["a"]=>
  80. int(10)
  81. ["b"]=>
  82. string(6) "string"
  83. ["c"]=>
  84. bool(true)
  85. ["d"]=>
  86. float(-2.34444)
  87. ["e"]=>
  88. array(7) {
  89. [0]=>
  90. int(1)
  91. [1]=>
  92. float(2.22)
  93. [2]=>
  94. string(6) "string"
  95. [3]=>
  96. bool(true)
  97. [4]=>
  98. array(0) {
  99. }
  100. [5]=>
  101. object(members)#%d (3) {
  102. ["var_private":"members":private]=>
  103. int(10)
  104. ["var_protected":protected]=>
  105. string(6) "string"
  106. ["var_public"]=>
  107. array(3) {
  108. [0]=>
  109. float(-100.123)
  110. [1]=>
  111. string(6) "string"
  112. [2]=>
  113. bool(true)
  114. }
  115. }
  116. [6]=>
  117. NULL
  118. }
  119. ["f"]=>
  120. object(nomembers)#%d (0) {
  121. }
  122. ["g"]=>
  123. NULL
  124. ["h"]=>
  125. NULL
  126. }
  127. After Serialization => string(108) "O:1:"D":8:{s:1:"a";i:1;s:1:"b";i:2;s:1:"c";i:3333;s:1:"d";i:444444;s:1:"e";N;s:1:"f";N;s:1:"g";N;s:1:"h";N;}"
  128. After Unserialization => object(D)#%d (8) {
  129. ["a"]=>
  130. int(1)
  131. ["b"]=>
  132. int(2)
  133. ["c"]=>
  134. int(3333)
  135. ["d"]=>
  136. int(444444)
  137. ["e"]=>
  138. NULL
  139. ["f"]=>
  140. NULL
  141. ["g"]=>
  142. NULL
  143. ["h"]=>
  144. NULL
  145. }
  146. After Serialization => string(223) "O:1:"D":8:{s:1:"a";d:0.5;s:1:"b";d:0.005000000000000000104083408558608425664715468883514404296875;s:1:"c";d:-1.3449999999999999733546474089962430298328399658203125;s:1:"d";d:1000500;s:1:"e";N;s:1:"f";N;s:1:"g";N;s:1:"h";N;}"
  147. After Unserialization => object(D)#%d (8) {
  148. ["a"]=>
  149. float(0.5)
  150. ["b"]=>
  151. float(0.005)
  152. ["c"]=>
  153. float(-1.345)
  154. ["d"]=>
  155. float(1000500)
  156. ["e"]=>
  157. NULL
  158. ["f"]=>
  159. NULL
  160. ["g"]=>
  161. NULL
  162. ["h"]=>
  163. NULL
  164. }
  165. After Serialization => string(100) "O:1:"D":8:{s:1:"a";b:1;s:1:"b";b:1;s:1:"c";b:0;s:1:"d";b:0;s:1:"e";N;s:1:"f";N;s:1:"g";N;s:1:"h";N;}"
  166. After Unserialization => object(D)#%d (8) {
  167. ["a"]=>
  168. bool(true)
  169. ["b"]=>
  170. bool(true)
  171. ["c"]=>
  172. bool(false)
  173. ["d"]=>
  174. bool(false)
  175. ["e"]=>
  176. NULL
  177. ["f"]=>
  178. NULL
  179. ["g"]=>
  180. NULL
  181. ["h"]=>
  182. NULL
  183. }
  184. After Serialization => string(126) "O:1:"D":8:{s:1:"a";s:1:"a";s:1:"b";s:1:"a";s:1:"c";s:6:"string";s:1:"d";s:6:"string";s:1:"e";N;s:1:"f";N;s:1:"g";N;s:1:"h";N;}"
  185. After Unserialization => object(D)#%d (8) {
  186. ["a"]=>
  187. string(1) "a"
  188. ["b"]=>
  189. string(1) "a"
  190. ["c"]=>
  191. string(6) "string"
  192. ["d"]=>
  193. string(6) "string"
  194. ["e"]=>
  195. NULL
  196. ["f"]=>
  197. NULL
  198. ["g"]=>
  199. NULL
  200. ["h"]=>
  201. NULL
  202. }
  203. After Serialization => string(300) "O:1:"D":8:{s:1:"a";a:0:{}s:1:"b";a:5:{i:0;i:1;i:1;d:2.221999999999999975131004248396493494510650634765625;i:2;b:1;i:3;b:0;i:4;s:6:"string";}s:1:"c";a:4:{i:0;O:9:"nomembers":0:{}i:1;N;i:2;N;i:3;s:0:"";}s:1:"d";a:1:{i:0;a:4:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;a:0:{}}}s:1:"e";N;s:1:"f";N;s:1:"g";N;s:1:"h";N;}"
  204. After Unserialization => object(D)#%d (8) {
  205. ["a"]=>
  206. array(0) {
  207. }
  208. ["b"]=>
  209. array(5) {
  210. [0]=>
  211. int(1)
  212. [1]=>
  213. float(2.222)
  214. [2]=>
  215. bool(true)
  216. [3]=>
  217. bool(false)
  218. [4]=>
  219. string(6) "string"
  220. }
  221. ["c"]=>
  222. array(4) {
  223. [0]=>
  224. object(nomembers)#%d (0) {
  225. }
  226. [1]=>
  227. NULL
  228. [2]=>
  229. NULL
  230. [3]=>
  231. string(0) ""
  232. }
  233. ["d"]=>
  234. array(1) {
  235. [0]=>
  236. array(4) {
  237. [0]=>
  238. int(1)
  239. [1]=>
  240. int(2)
  241. [2]=>
  242. int(3)
  243. [3]=>
  244. array(0) {
  245. }
  246. }
  247. }
  248. ["e"]=>
  249. NULL
  250. ["f"]=>
  251. NULL
  252. ["g"]=>
  253. NULL
  254. ["h"]=>
  255. NULL
  256. }
  257. After Serialization => string(103) "O:1:"D":8:{s:1:"a";N;s:1:"b";N;s:1:"c";s:0:"";s:1:"d";s:1:"�";s:1:"e";N;s:1:"f";N;s:1:"g";N;s:1:"h";N;}"
  258. After Unserialization => object(D)#%d (8) {
  259. ["a"]=>
  260. NULL
  261. ["b"]=>
  262. NULL
  263. ["c"]=>
  264. string(0) ""
  265. ["d"]=>
  266. string(1) "�"
  267. ["e"]=>
  268. NULL
  269. ["f"]=>
  270. NULL
  271. ["g"]=>
  272. NULL
  273. ["h"]=>
  274. NULL
  275. }
  276. After Serialization => string(303) "O:1:"D":8:{s:1:"a";O:7:"members":3:{s:20:"�members�var_private";i:10;s:16:"�*�var_protected";s:6:"string";s:10:"var_public";a:3:{i:0;d:-100.1230000000000046611603465862572193145751953125;i:1;s:6:"string";i:2;b:1;}}s:1:"b";O:9:"nomembers":0:{}s:1:"c";N;s:1:"d";N;s:1:"e";N;s:1:"f";N;s:1:"g";N;s:1:"h";N;}"
  277. After Unserialization => object(D)#%d (8) {
  278. ["a"]=>
  279. object(members)#%d (3) {
  280. ["var_private":"members":private]=>
  281. int(10)
  282. ["var_protected":protected]=>
  283. string(6) "string"
  284. ["var_public"]=>
  285. array(3) {
  286. [0]=>
  287. float(-100.123)
  288. [1]=>
  289. string(6) "string"
  290. [2]=>
  291. bool(true)
  292. }
  293. }
  294. ["b"]=>
  295. object(nomembers)#%d (0) {
  296. }
  297. ["c"]=>
  298. NULL
  299. ["d"]=>
  300. NULL
  301. ["e"]=>
  302. NULL
  303. ["f"]=>
  304. NULL
  305. ["g"]=>
  306. NULL
  307. ["h"]=>
  308. NULL
  309. }
  310. Done