gettimeofday_variation1.phpt 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. --TEST--
  2. Test gettimeofday() function : usage variation - Passing unexpected values to get_as_float argument
  3. --FILE--
  4. <?php
  5. /* Prototype : array gettimeofday([bool get_as_float])
  6. * Description: Returns the current time as array
  7. * Source code: ext/standard/microtime.c
  8. * Alias to functions:
  9. */
  10. echo "*** Testing gettimeofday() : usage variation ***\n";
  11. date_default_timezone_set("Asia/Calcutta");
  12. //get an unset variable
  13. $unset_var = 10;
  14. unset ($unset_var);
  15. // define some classes
  16. class classWithToString
  17. {
  18. public function __toString() {
  19. return "Class A object";
  20. }
  21. }
  22. class classWithoutToString
  23. {
  24. }
  25. // heredoc string
  26. $heredoc = <<<EOT
  27. hello world
  28. EOT;
  29. // add arrays
  30. $index_array = array (1, 2, 3);
  31. $assoc_array = array ('one' => 1, 'two' => 2);
  32. //array of values to iterate over
  33. $inputs = array(
  34. // int data
  35. 'int 0' => 0,
  36. 'int 1' => 1,
  37. 'int 12345' => 12345,
  38. 'int -12345' => -12345,
  39. // float data
  40. 'float 10.5' => 10.5,
  41. 'float -10.5' => -10.5,
  42. 'float 12.3456789000e10' => 12.3456789000e10,
  43. 'float -12.3456789000e10' => -12.3456789000e10,
  44. 'float .5' => .5,
  45. // array data
  46. 'empty array' => array(),
  47. 'int indexed array' => $index_array,
  48. 'associative array' => $assoc_array,
  49. 'nested arrays' => array('foo', $index_array, $assoc_array),
  50. // null data
  51. 'uppercase NULL' => NULL,
  52. 'lowercase null' => null,
  53. // boolean data
  54. 'lowercase true' => true,
  55. 'lowercase false' =>false,
  56. 'uppercase TRUE' =>TRUE,
  57. 'uppercase FALSE' =>FALSE,
  58. // empty data
  59. 'empty string DQ' => "",
  60. 'empty string SQ' => '',
  61. // string data
  62. 'string DQ' => "string",
  63. 'string SQ' => 'string',
  64. 'mixed case string' => "sTrInG",
  65. 'heredoc' => $heredoc,
  66. // object data
  67. 'instance of classWithToString' => new classWithToString(),
  68. 'instance of classWithoutToString' => new classWithoutToString(),
  69. // undefined data
  70. 'undefined var' => @$undefined_var,
  71. // unset data
  72. 'unset var' => @$unset_var,
  73. );
  74. // loop through each element of the array for get_as_float
  75. foreach($inputs as $key =>$value) {
  76. echo "\n--$key--\n";
  77. var_dump( gettimeofday($value) );
  78. };
  79. ?>
  80. ===DONE===
  81. --EXPECTF--
  82. *** Testing gettimeofday() : usage variation ***
  83. --int 0--
  84. array(4) {
  85. ["sec"]=>
  86. int(%d)
  87. ["usec"]=>
  88. int(%d)
  89. ["minuteswest"]=>
  90. int(-330)
  91. ["dsttime"]=>
  92. int(0)
  93. }
  94. --int 1--
  95. float(%f)
  96. --int 12345--
  97. float(%f)
  98. --int -12345--
  99. float(%f)
  100. --float 10.5--
  101. float(%f)
  102. --float -10.5--
  103. float(%f)
  104. --float 12.3456789000e10--
  105. float(%f)
  106. --float -12.3456789000e10--
  107. float(%f)
  108. --float .5--
  109. float(%f)
  110. --empty array--
  111. Warning: gettimeofday() expects parameter 1 to be boolean, array given in %s on line %d
  112. NULL
  113. --int indexed array--
  114. Warning: gettimeofday() expects parameter 1 to be boolean, array given in %s on line %d
  115. NULL
  116. --associative array--
  117. Warning: gettimeofday() expects parameter 1 to be boolean, array given in %s on line %d
  118. NULL
  119. --nested arrays--
  120. Warning: gettimeofday() expects parameter 1 to be boolean, array given in %s on line %d
  121. NULL
  122. --uppercase NULL--
  123. array(4) {
  124. ["sec"]=>
  125. int(%d)
  126. ["usec"]=>
  127. int(%d)
  128. ["minuteswest"]=>
  129. int(-330)
  130. ["dsttime"]=>
  131. int(0)
  132. }
  133. --lowercase null--
  134. array(4) {
  135. ["sec"]=>
  136. int(%d)
  137. ["usec"]=>
  138. int(%d)
  139. ["minuteswest"]=>
  140. int(-330)
  141. ["dsttime"]=>
  142. int(0)
  143. }
  144. --lowercase true--
  145. float(%f)
  146. --lowercase false--
  147. array(4) {
  148. ["sec"]=>
  149. int(%d)
  150. ["usec"]=>
  151. int(%d)
  152. ["minuteswest"]=>
  153. int(-330)
  154. ["dsttime"]=>
  155. int(0)
  156. }
  157. --uppercase TRUE--
  158. float(%f)
  159. --uppercase FALSE--
  160. array(4) {
  161. ["sec"]=>
  162. int(%d)
  163. ["usec"]=>
  164. int(%d)
  165. ["minuteswest"]=>
  166. int(-330)
  167. ["dsttime"]=>
  168. int(0)
  169. }
  170. --empty string DQ--
  171. array(4) {
  172. ["sec"]=>
  173. int(%d)
  174. ["usec"]=>
  175. int(%d)
  176. ["minuteswest"]=>
  177. int(-330)
  178. ["dsttime"]=>
  179. int(0)
  180. }
  181. --empty string SQ--
  182. array(4) {
  183. ["sec"]=>
  184. int(%d)
  185. ["usec"]=>
  186. int(%d)
  187. ["minuteswest"]=>
  188. int(-330)
  189. ["dsttime"]=>
  190. int(0)
  191. }
  192. --string DQ--
  193. float(%f)
  194. --string SQ--
  195. float(%f)
  196. --mixed case string--
  197. float(%f)
  198. --heredoc--
  199. float(%f)
  200. --instance of classWithToString--
  201. Warning: gettimeofday() expects parameter 1 to be boolean, object given in %s on line %d
  202. NULL
  203. --instance of classWithoutToString--
  204. Warning: gettimeofday() expects parameter 1 to be boolean, object given in %s on line %d
  205. NULL
  206. --undefined var--
  207. array(4) {
  208. ["sec"]=>
  209. int(%d)
  210. ["usec"]=>
  211. int(%d)
  212. ["minuteswest"]=>
  213. int(-330)
  214. ["dsttime"]=>
  215. int(0)
  216. }
  217. --unset var--
  218. array(4) {
  219. ["sec"]=>
  220. int(%d)
  221. ["usec"]=>
  222. int(%d)
  223. ["minuteswest"]=>
  224. int(-330)
  225. ["dsttime"]=>
  226. int(0)
  227. }
  228. ===DONE===