session_decode_basic_serialize.phpt 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. --TEST--
  2. Test session_decode() function : basic functionality
  3. --SKIPIF--
  4. <?php include('skipif.inc'); ?>
  5. --FILE--
  6. <?php
  7. ob_start();
  8. /*
  9. * Prototype : string session_decode(void)
  10. * Description : Decodes session data from a string
  11. * Source code : ext/session/session.c
  12. */
  13. echo "*** Testing session_decode() : basic functionality ***\n";
  14. // Get an unset variable
  15. $unset_var = 10;
  16. unset($unset_var);
  17. class classA
  18. {
  19. public function __toString() {
  20. return "Hello World!";
  21. }
  22. }
  23. $heredoc = <<<EOT
  24. Hello World!
  25. EOT;
  26. $fp = fopen(__FILE__, "r");
  27. // Unexpected values to be passed as arguments
  28. $inputs = array(
  29. // Integer data
  30. /*1*/ 0,
  31. 1,
  32. 12345,
  33. -2345,
  34. // Float data
  35. /*5*/ 10.5,
  36. -10.5,
  37. 12.3456789000e10,
  38. 12.3456789000E-10,
  39. .5,
  40. // Null data
  41. /*10*/ NULL,
  42. null,
  43. // Boolean data
  44. /*12*/ true,
  45. false,
  46. TRUE,
  47. FALSE,
  48. // Empty strings
  49. /*16*/ "",
  50. '',
  51. // Invalid string data
  52. /*18*/ "Nothing",
  53. 'Nothing',
  54. $heredoc,
  55. // Object data
  56. /*21*/ new classA(),
  57. // Undefined data
  58. /*22*/ @$undefined_var,
  59. // Unset data
  60. /*23*/ @$unset_var,
  61. // Resource variable
  62. /*24*/ $fp
  63. );
  64. ini_set('session.serialize_handler', 'php_serialize');
  65. var_dump(session_start());
  66. $iterator = 1;
  67. foreach($inputs as $input) {
  68. echo "\n-- Iteration $iterator --\n";
  69. $_SESSION["data"] = $input;
  70. $encoded = session_encode();
  71. var_dump(session_decode($encoded));
  72. var_dump($_SESSION);
  73. $iterator++;
  74. };
  75. var_dump(session_destroy());
  76. fclose($fp);
  77. echo "Done";
  78. ob_end_flush();
  79. ?>
  80. --EXPECTF--
  81. *** Testing session_decode() : basic functionality ***
  82. bool(true)
  83. -- Iteration 1 --
  84. bool(true)
  85. array(1) {
  86. ["data"]=>
  87. int(0)
  88. }
  89. -- Iteration 2 --
  90. bool(true)
  91. array(1) {
  92. ["data"]=>
  93. int(1)
  94. }
  95. -- Iteration 3 --
  96. bool(true)
  97. array(1) {
  98. ["data"]=>
  99. int(12345)
  100. }
  101. -- Iteration 4 --
  102. bool(true)
  103. array(1) {
  104. ["data"]=>
  105. int(-2345)
  106. }
  107. -- Iteration 5 --
  108. bool(true)
  109. array(1) {
  110. ["data"]=>
  111. float(10.5)
  112. }
  113. -- Iteration 6 --
  114. bool(true)
  115. array(1) {
  116. ["data"]=>
  117. float(-10.5)
  118. }
  119. -- Iteration 7 --
  120. bool(true)
  121. array(1) {
  122. ["data"]=>
  123. float(123456789000)
  124. }
  125. -- Iteration 8 --
  126. bool(true)
  127. array(1) {
  128. ["data"]=>
  129. float(1.23456789E-9)
  130. }
  131. -- Iteration 9 --
  132. bool(true)
  133. array(1) {
  134. ["data"]=>
  135. float(0.5)
  136. }
  137. -- Iteration 10 --
  138. bool(true)
  139. array(1) {
  140. ["data"]=>
  141. NULL
  142. }
  143. -- Iteration 11 --
  144. bool(true)
  145. array(1) {
  146. ["data"]=>
  147. NULL
  148. }
  149. -- Iteration 12 --
  150. bool(true)
  151. array(1) {
  152. ["data"]=>
  153. bool(true)
  154. }
  155. -- Iteration 13 --
  156. bool(true)
  157. array(1) {
  158. ["data"]=>
  159. bool(false)
  160. }
  161. -- Iteration 14 --
  162. bool(true)
  163. array(1) {
  164. ["data"]=>
  165. bool(true)
  166. }
  167. -- Iteration 15 --
  168. bool(true)
  169. array(1) {
  170. ["data"]=>
  171. bool(false)
  172. }
  173. -- Iteration 16 --
  174. bool(true)
  175. array(1) {
  176. ["data"]=>
  177. string(0) ""
  178. }
  179. -- Iteration 17 --
  180. bool(true)
  181. array(1) {
  182. ["data"]=>
  183. string(0) ""
  184. }
  185. -- Iteration 18 --
  186. bool(true)
  187. array(1) {
  188. ["data"]=>
  189. string(7) "Nothing"
  190. }
  191. -- Iteration 19 --
  192. bool(true)
  193. array(1) {
  194. ["data"]=>
  195. string(7) "Nothing"
  196. }
  197. -- Iteration 20 --
  198. bool(true)
  199. array(1) {
  200. ["data"]=>
  201. string(12) "Hello World!"
  202. }
  203. -- Iteration 21 --
  204. bool(true)
  205. array(1) {
  206. ["data"]=>
  207. object(classA)#2 (0) {
  208. }
  209. }
  210. -- Iteration 22 --
  211. bool(true)
  212. array(1) {
  213. ["data"]=>
  214. NULL
  215. }
  216. -- Iteration 23 --
  217. bool(true)
  218. array(1) {
  219. ["data"]=>
  220. NULL
  221. }
  222. -- Iteration 24 --
  223. bool(true)
  224. array(1) {
  225. ["data"]=>
  226. int(0)
  227. }
  228. bool(true)
  229. Done