session_id_error.phpt 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. --TEST--
  2. Test session_id() function : error functionality
  3. --SKIPIF--
  4. <?php include('skipif.inc'); ?>
  5. --FILE--
  6. <?php
  7. ob_start();
  8. /*
  9. * Prototype : string session_id([string $id])
  10. * Description : Get and/or set the current session id
  11. * Source code : ext/session/session.c
  12. */
  13. echo "*** Testing session_id() : 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. $iterator = 1;
  65. foreach($inputs as $input) {
  66. echo "\n-- Iteration $iterator --\n";
  67. var_dump(session_id($input));
  68. $iterator++;
  69. };
  70. fclose($fp);
  71. echo "Done";
  72. ob_end_flush();
  73. ?>
  74. --EXPECTF--
  75. *** Testing session_id() : error functionality ***
  76. -- Iteration 1 --
  77. string(0) ""
  78. -- Iteration 2 --
  79. string(1) "0"
  80. -- Iteration 3 --
  81. string(1) "1"
  82. -- Iteration 4 --
  83. string(5) "12345"
  84. -- Iteration 5 --
  85. string(5) "-2345"
  86. -- Iteration 6 --
  87. string(4) "10.5"
  88. -- Iteration 7 --
  89. string(5) "-10.5"
  90. -- Iteration 8 --
  91. string(12) "123456789000"
  92. -- Iteration 9 --
  93. string(13) "1.23456789E-9"
  94. -- Iteration 10 --
  95. string(3) "0.5"
  96. -- Iteration 11 --
  97. string(0) ""
  98. -- Iteration 12 --
  99. string(0) ""
  100. -- Iteration 13 --
  101. string(1) "1"
  102. -- Iteration 14 --
  103. string(0) ""
  104. -- Iteration 15 --
  105. string(1) "1"
  106. -- Iteration 16 --
  107. string(0) ""
  108. -- Iteration 17 --
  109. string(0) ""
  110. -- Iteration 18 --
  111. string(0) ""
  112. -- Iteration 19 --
  113. string(7) "Nothing"
  114. -- Iteration 20 --
  115. string(7) "Nothing"
  116. -- Iteration 21 --
  117. string(12) "Hello World!"
  118. -- Iteration 22 --
  119. string(12) "Hello World!"
  120. -- Iteration 23 --
  121. string(0) ""
  122. -- Iteration 24 --
  123. Warning: session_id() expects parameter 1 to be string, resource given in %s on line %d
  124. NULL
  125. Done