session_decode_error.phpt 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. --TEST--
  2. Test session_decode() function : error 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() : error 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. var_dump(session_start());
  65. $iterator = 1;
  66. foreach($inputs as $input) {
  67. echo "\n-- Iteration $iterator --\n";
  68. var_dump(session_decode($input));
  69. var_dump($_SESSION);
  70. $iterator++;
  71. };
  72. var_dump(session_destroy());
  73. fclose($fp);
  74. echo "Done";
  75. ob_end_flush();
  76. ?>
  77. --EXPECTF--
  78. *** Testing session_decode() : error functionality ***
  79. bool(true)
  80. -- Iteration 1 --
  81. bool(true)
  82. array(0) {
  83. }
  84. -- Iteration 2 --
  85. bool(true)
  86. array(0) {
  87. }
  88. -- Iteration 3 --
  89. bool(true)
  90. array(0) {
  91. }
  92. -- Iteration 4 --
  93. bool(true)
  94. array(0) {
  95. }
  96. -- Iteration 5 --
  97. bool(true)
  98. array(0) {
  99. }
  100. -- Iteration 6 --
  101. bool(true)
  102. array(0) {
  103. }
  104. -- Iteration 7 --
  105. bool(true)
  106. array(0) {
  107. }
  108. -- Iteration 8 --
  109. bool(true)
  110. array(0) {
  111. }
  112. -- Iteration 9 --
  113. bool(true)
  114. array(0) {
  115. }
  116. -- Iteration 10 --
  117. bool(true)
  118. array(0) {
  119. }
  120. -- Iteration 11 --
  121. bool(true)
  122. array(0) {
  123. }
  124. -- Iteration 12 --
  125. bool(true)
  126. array(0) {
  127. }
  128. -- Iteration 13 --
  129. bool(true)
  130. array(0) {
  131. }
  132. -- Iteration 14 --
  133. bool(true)
  134. array(0) {
  135. }
  136. -- Iteration 15 --
  137. bool(true)
  138. array(0) {
  139. }
  140. -- Iteration 16 --
  141. bool(true)
  142. array(0) {
  143. }
  144. -- Iteration 17 --
  145. bool(true)
  146. array(0) {
  147. }
  148. -- Iteration 18 --
  149. bool(true)
  150. array(0) {
  151. }
  152. -- Iteration 19 --
  153. bool(true)
  154. array(0) {
  155. }
  156. -- Iteration 20 --
  157. bool(true)
  158. array(0) {
  159. }
  160. -- Iteration 21 --
  161. bool(true)
  162. array(0) {
  163. }
  164. -- Iteration 22 --
  165. bool(true)
  166. array(0) {
  167. }
  168. -- Iteration 23 --
  169. bool(true)
  170. array(0) {
  171. }
  172. -- Iteration 24 --
  173. Warning: session_decode() expects parameter 1 to be string, resource given in %s on line %d
  174. NULL
  175. array(0) {
  176. }
  177. bool(true)
  178. Done