session_name_error.phpt 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. --TEST--
  2. Test session_name() function : error functionality
  3. --INI--
  4. session.save_path=
  5. session.name=PHPSESSID
  6. --SKIPIF--
  7. <?php include('skipif.inc'); ?>
  8. --FILE--
  9. <?php
  10. ob_start();
  11. /*
  12. * Prototype : string session_name([string $name])
  13. * Description : Get and/or set the current session name
  14. * Source code : ext/session/session.c
  15. */
  16. echo "*** Testing session_name() : error functionality ***\n";
  17. // Get an unset variable
  18. $unset_var = 10;
  19. unset($unset_var);
  20. class classA
  21. {
  22. public function __toString() {
  23. return "Hello World!";
  24. }
  25. }
  26. $heredoc = <<<EOT
  27. Hello World!
  28. EOT;
  29. $fp = fopen(__FILE__, "r");
  30. // Unexpected values to be passed as arguments
  31. $inputs = array(
  32. // Integer data
  33. /*1*/ 0,
  34. 1,
  35. 12345,
  36. -2345,
  37. // Float data
  38. /*5*/ 10.5,
  39. -10.5,
  40. 12.3456789000e10,
  41. 12.3456789000E-10,
  42. .5,
  43. // Null data
  44. /*10*/ NULL,
  45. null,
  46. // Boolean data
  47. /*12*/ true,
  48. false,
  49. TRUE,
  50. FALSE,
  51. // Empty strings
  52. /*16*/ "",
  53. '',
  54. // Invalid string data
  55. /*18*/ "Nothing",
  56. 'Nothing',
  57. $heredoc,
  58. // Object data
  59. /*21*/ new classA(),
  60. // Undefined data
  61. /*22*/ @$undefined_var,
  62. // Unset data
  63. /*23*/ @$unset_var,
  64. // Resource variable
  65. /*24*/ $fp
  66. );
  67. $iterator = 1;
  68. foreach($inputs as $input) {
  69. echo "\n-- Iteration $iterator --\n";
  70. var_dump($input, session_name($input));
  71. $iterator++;
  72. };
  73. fclose($fp);
  74. echo "Done";
  75. ob_end_flush();
  76. ?>
  77. --EXPECTF--
  78. *** Testing session_name() : error functionality ***
  79. -- Iteration 1 --
  80. Warning: session_name(): session.name cannot be a numeric or empty '0' in %s on line %d
  81. int(0)
  82. string(9) "PHPSESSID"
  83. -- Iteration 2 --
  84. Warning: session_name(): session.name cannot be a numeric or empty '1' in %s on line %d
  85. int(1)
  86. string(9) "PHPSESSID"
  87. -- Iteration 3 --
  88. Warning: session_name(): session.name cannot be a numeric or empty '12345' in %s on line %d
  89. int(12345)
  90. string(9) "PHPSESSID"
  91. -- Iteration 4 --
  92. Warning: session_name(): session.name cannot be a numeric or empty '-2345' in %s on line %d
  93. int(-2345)
  94. string(9) "PHPSESSID"
  95. -- Iteration 5 --
  96. Warning: session_name(): session.name cannot be a numeric or empty '10.5' in %s on line %d
  97. float(10.5)
  98. string(9) "PHPSESSID"
  99. -- Iteration 6 --
  100. Warning: session_name(): session.name cannot be a numeric or empty '-10.5' in %s on line %d
  101. float(-10.5)
  102. string(9) "PHPSESSID"
  103. -- Iteration 7 --
  104. Warning: session_name(): session.name cannot be a numeric or empty '123456789000' in %s on line %d
  105. float(123456789000)
  106. string(9) "PHPSESSID"
  107. -- Iteration 8 --
  108. Warning: session_name(): session.name cannot be a numeric or empty '1.23456789E-9' in %s on line %d
  109. float(1.23456789E-9)
  110. string(9) "PHPSESSID"
  111. -- Iteration 9 --
  112. Warning: session_name(): session.name cannot be a numeric or empty '0.5' in %s on line %d
  113. float(0.5)
  114. string(9) "PHPSESSID"
  115. -- Iteration 10 --
  116. Warning: session_name(): session.name cannot be a numeric or empty '' in %s on line %d
  117. NULL
  118. string(9) "PHPSESSID"
  119. -- Iteration 11 --
  120. Warning: session_name(): session.name cannot be a numeric or empty '' in %s on line %d
  121. NULL
  122. string(9) "PHPSESSID"
  123. -- Iteration 12 --
  124. Warning: session_name(): session.name cannot be a numeric or empty '1' in %s on line %d
  125. bool(true)
  126. string(9) "PHPSESSID"
  127. -- Iteration 13 --
  128. Warning: session_name(): session.name cannot be a numeric or empty '' in %s on line %d
  129. bool(false)
  130. string(9) "PHPSESSID"
  131. -- Iteration 14 --
  132. Warning: session_name(): session.name cannot be a numeric or empty '1' in %s on line %d
  133. bool(true)
  134. string(9) "PHPSESSID"
  135. -- Iteration 15 --
  136. Warning: session_name(): session.name cannot be a numeric or empty '' in %s on line %d
  137. bool(false)
  138. string(9) "PHPSESSID"
  139. -- Iteration 16 --
  140. Warning: session_name(): session.name cannot be a numeric or empty '' in %s on line %d
  141. string(0) ""
  142. string(9) "PHPSESSID"
  143. -- Iteration 17 --
  144. Warning: session_name(): session.name cannot be a numeric or empty '' in %s on line %d
  145. string(0) ""
  146. string(9) "PHPSESSID"
  147. -- Iteration 18 --
  148. string(7) "Nothing"
  149. string(9) "PHPSESSID"
  150. -- Iteration 19 --
  151. string(7) "Nothing"
  152. string(7) "Nothing"
  153. -- Iteration 20 --
  154. string(12) "Hello World!"
  155. string(7) "Nothing"
  156. -- Iteration 21 --
  157. object(classA)#1 (0) {
  158. }
  159. string(12) "Hello World!"
  160. -- Iteration 22 --
  161. Warning: session_name(): session.name cannot be a numeric or empty '' in %s on line %d
  162. NULL
  163. string(12) "Hello World!"
  164. -- Iteration 23 --
  165. Warning: session_name(): session.name cannot be a numeric or empty '' in %s on line %d
  166. NULL
  167. string(12) "Hello World!"
  168. -- Iteration 24 --
  169. Warning: session_name() expects parameter 1 to be string, resource given in %s on line %d
  170. resource(%d) of type (stream)
  171. NULL
  172. Done