session_encode_basic.phpt 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. --TEST--
  2. Test session_encode() function : basic functionality
  3. --INI--
  4. serialize_precision=100
  5. --SKIPIF--
  6. <?php include('skipif.inc'); ?>
  7. --FILE--
  8. <?php
  9. ob_start();
  10. /*
  11. * Prototype : string session_encode(void)
  12. * Description : Encodes the current session data as a string
  13. * Source code : ext/session/session.c
  14. */
  15. echo "*** Testing session_encode() : basic functionality ***\n";
  16. // Get an unset variable
  17. $unset_var = 10;
  18. unset($unset_var);
  19. class classA
  20. {
  21. public function __toString() {
  22. return "Hello World!";
  23. }
  24. }
  25. $heredoc = <<<EOT
  26. Hello World!
  27. EOT;
  28. $fp = fopen(__FILE__, "r");
  29. // Unexpected values to be passed as arguments
  30. $inputs = array(
  31. // Integer data
  32. /*1*/ 0,
  33. 1,
  34. 12345,
  35. -2345,
  36. // Float data
  37. /*5*/ 10.5,
  38. -10.5,
  39. 12.3456789000e10,
  40. 12.3456789000E-10,
  41. .5,
  42. // Null data
  43. /*10*/ NULL,
  44. null,
  45. // Boolean data
  46. /*12*/ true,
  47. false,
  48. TRUE,
  49. FALSE,
  50. // Empty strings
  51. /*16*/ "",
  52. '',
  53. // Invalid string data
  54. /*18*/ "Nothing",
  55. 'Nothing',
  56. $heredoc,
  57. // Object data
  58. /*21*/ new classA(),
  59. // Undefined data
  60. /*22*/ @$undefined_var,
  61. // Unset data
  62. /*23*/ @$unset_var,
  63. // Resource variable
  64. /*24*/ $fp
  65. );
  66. var_dump(session_start());
  67. $iterator = 1;
  68. foreach($inputs as $input) {
  69. echo "\n-- Iteration $iterator --\n";
  70. $_SESSION["data"] = $input;
  71. var_dump(session_encode());
  72. $iterator++;
  73. };
  74. var_dump(session_destroy());
  75. fclose($fp);
  76. echo "Done";
  77. ob_end_flush();
  78. ?>
  79. --EXPECTF--
  80. *** Testing session_encode() : basic functionality ***
  81. bool(true)
  82. -- Iteration 1 --
  83. string(9) "data|i:0;"
  84. -- Iteration 2 --
  85. string(9) "data|i:1;"
  86. -- Iteration 3 --
  87. string(13) "data|i:12345;"
  88. -- Iteration 4 --
  89. string(13) "data|i:-2345;"
  90. -- Iteration 5 --
  91. string(12) "data|d:10.5;"
  92. -- Iteration 6 --
  93. string(13) "data|d:-10.5;"
  94. -- Iteration 7 --
  95. string(20) "data|d:123456789000;"
  96. -- Iteration 8 --
  97. string(%d) "data|d:1.2345678899999999145113427164344339914681114578343112953007221221923828125E-9;"
  98. -- Iteration 9 --
  99. string(11) "data|d:0.5;"
  100. -- Iteration 10 --
  101. string(7) "data|N;"
  102. -- Iteration 11 --
  103. string(7) "data|N;"
  104. -- Iteration 12 --
  105. string(9) "data|b:1;"
  106. -- Iteration 13 --
  107. string(9) "data|b:0;"
  108. -- Iteration 14 --
  109. string(9) "data|b:1;"
  110. -- Iteration 15 --
  111. string(9) "data|b:0;"
  112. -- Iteration 16 --
  113. string(12) "data|s:0:"";"
  114. -- Iteration 17 --
  115. string(12) "data|s:0:"";"
  116. -- Iteration 18 --
  117. string(19) "data|s:7:"Nothing";"
  118. -- Iteration 19 --
  119. string(19) "data|s:7:"Nothing";"
  120. -- Iteration 20 --
  121. string(25) "data|s:12:"Hello World!";"
  122. -- Iteration 21 --
  123. string(22) "data|O:6:"classA":0:{}"
  124. -- Iteration 22 --
  125. string(7) "data|N;"
  126. -- Iteration 23 --
  127. string(7) "data|N;"
  128. -- Iteration 24 --
  129. string(9) "data|i:0;"
  130. bool(true)
  131. Done