getdate_variation1.phpt 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. --TEST--
  2. Test getdate() function : usage variation - Passing unexpected values to first argument timestamp.
  3. --FILE--
  4. <?php
  5. /* Prototype : array getdate([int timestamp])
  6. * Description: Get date/time information
  7. * Source code: ext/date/php_date.c
  8. * Alias to functions:
  9. */
  10. echo "*** Testing getdate() : usage variation ***\n";
  11. //Set the default time zone
  12. date_default_timezone_set("Asia/Calcutta");
  13. //get an unset variable
  14. $unset_var = 10;
  15. unset ($unset_var);
  16. // define some classes
  17. class classWithToString
  18. {
  19. public function __toString() {
  20. return "Class A object";
  21. }
  22. }
  23. class classWithoutToString
  24. {
  25. }
  26. // heredoc string
  27. $heredoc = <<<EOT
  28. hello world
  29. EOT;
  30. // add arrays
  31. $index_array = array (1, 2, 3);
  32. $assoc_array = array ('one' => 1, 'two' => 2);
  33. //array of values to iterate over
  34. $inputs = array(
  35. // float data
  36. 'float 10.5' => 10.5,
  37. 'float -10.5' => -10.5,
  38. 'float .5' => .5,
  39. // array data
  40. 'empty array' => array(),
  41. 'int indexed array' => $index_array,
  42. 'associative array' => $assoc_array,
  43. 'nested arrays' => array('foo', $index_array, $assoc_array),
  44. // null data
  45. 'uppercase NULL' => NULL,
  46. 'lowercase null' => null,
  47. // boolean data
  48. 'lowercase true' => true,
  49. 'lowercase false' =>false,
  50. 'uppercase TRUE' =>TRUE,
  51. 'uppercase FALSE' =>FALSE,
  52. // empty data
  53. 'empty string DQ' => "",
  54. 'empty string SQ' => '',
  55. // string data
  56. 'string DQ' => "string",
  57. 'string SQ' => 'string',
  58. 'mixed case string' => "sTrInG",
  59. 'heredoc' => $heredoc,
  60. // object data
  61. 'instance of classWithToString' => new classWithToString(),
  62. 'instance of classWithoutToString' => new classWithoutToString(),
  63. // undefined data
  64. 'undefined var' => @$undefined_var,
  65. // unset data
  66. 'unset var' => @$unset_var,
  67. );
  68. // loop through each element of the array for timestamp
  69. foreach($inputs as $key =>$value) {
  70. echo "\n--$key--\n";
  71. var_dump( getdate($value) );
  72. };
  73. ?>
  74. ===DONE===
  75. --EXPECTF--
  76. *** Testing getdate() : usage variation ***
  77. --float 10.5--
  78. array(11) {
  79. ["seconds"]=>
  80. int(10)
  81. ["minutes"]=>
  82. int(30)
  83. ["hours"]=>
  84. int(5)
  85. ["mday"]=>
  86. int(1)
  87. ["wday"]=>
  88. int(4)
  89. ["mon"]=>
  90. int(1)
  91. ["year"]=>
  92. int(1970)
  93. ["yday"]=>
  94. int(0)
  95. ["weekday"]=>
  96. string(8) "Thursday"
  97. ["month"]=>
  98. string(7) "January"
  99. [0]=>
  100. int(10)
  101. }
  102. --float -10.5--
  103. array(11) {
  104. ["seconds"]=>
  105. int(50)
  106. ["minutes"]=>
  107. int(29)
  108. ["hours"]=>
  109. int(5)
  110. ["mday"]=>
  111. int(1)
  112. ["wday"]=>
  113. int(4)
  114. ["mon"]=>
  115. int(1)
  116. ["year"]=>
  117. int(1970)
  118. ["yday"]=>
  119. int(0)
  120. ["weekday"]=>
  121. string(8) "Thursday"
  122. ["month"]=>
  123. string(7) "January"
  124. [0]=>
  125. int(-10)
  126. }
  127. --float .5--
  128. array(11) {
  129. ["seconds"]=>
  130. int(0)
  131. ["minutes"]=>
  132. int(30)
  133. ["hours"]=>
  134. int(5)
  135. ["mday"]=>
  136. int(1)
  137. ["wday"]=>
  138. int(4)
  139. ["mon"]=>
  140. int(1)
  141. ["year"]=>
  142. int(1970)
  143. ["yday"]=>
  144. int(0)
  145. ["weekday"]=>
  146. string(8) "Thursday"
  147. ["month"]=>
  148. string(7) "January"
  149. [0]=>
  150. int(0)
  151. }
  152. --empty array--
  153. Warning: getdate() expects parameter 1 to be long, array given in %s on line %d
  154. bool(false)
  155. --int indexed array--
  156. Warning: getdate() expects parameter 1 to be long, array given in %s on line %d
  157. bool(false)
  158. --associative array--
  159. Warning: getdate() expects parameter 1 to be long, array given in %s on line %d
  160. bool(false)
  161. --nested arrays--
  162. Warning: getdate() expects parameter 1 to be long, array given in %s on line %d
  163. bool(false)
  164. --uppercase NULL--
  165. array(11) {
  166. ["seconds"]=>
  167. int(0)
  168. ["minutes"]=>
  169. int(30)
  170. ["hours"]=>
  171. int(5)
  172. ["mday"]=>
  173. int(1)
  174. ["wday"]=>
  175. int(4)
  176. ["mon"]=>
  177. int(1)
  178. ["year"]=>
  179. int(1970)
  180. ["yday"]=>
  181. int(0)
  182. ["weekday"]=>
  183. string(8) "Thursday"
  184. ["month"]=>
  185. string(7) "January"
  186. [0]=>
  187. int(0)
  188. }
  189. --lowercase null--
  190. array(11) {
  191. ["seconds"]=>
  192. int(0)
  193. ["minutes"]=>
  194. int(30)
  195. ["hours"]=>
  196. int(5)
  197. ["mday"]=>
  198. int(1)
  199. ["wday"]=>
  200. int(4)
  201. ["mon"]=>
  202. int(1)
  203. ["year"]=>
  204. int(1970)
  205. ["yday"]=>
  206. int(0)
  207. ["weekday"]=>
  208. string(8) "Thursday"
  209. ["month"]=>
  210. string(7) "January"
  211. [0]=>
  212. int(0)
  213. }
  214. --lowercase true--
  215. array(11) {
  216. ["seconds"]=>
  217. int(1)
  218. ["minutes"]=>
  219. int(30)
  220. ["hours"]=>
  221. int(5)
  222. ["mday"]=>
  223. int(1)
  224. ["wday"]=>
  225. int(4)
  226. ["mon"]=>
  227. int(1)
  228. ["year"]=>
  229. int(1970)
  230. ["yday"]=>
  231. int(0)
  232. ["weekday"]=>
  233. string(8) "Thursday"
  234. ["month"]=>
  235. string(7) "January"
  236. [0]=>
  237. int(1)
  238. }
  239. --lowercase false--
  240. array(11) {
  241. ["seconds"]=>
  242. int(0)
  243. ["minutes"]=>
  244. int(30)
  245. ["hours"]=>
  246. int(5)
  247. ["mday"]=>
  248. int(1)
  249. ["wday"]=>
  250. int(4)
  251. ["mon"]=>
  252. int(1)
  253. ["year"]=>
  254. int(1970)
  255. ["yday"]=>
  256. int(0)
  257. ["weekday"]=>
  258. string(8) "Thursday"
  259. ["month"]=>
  260. string(7) "January"
  261. [0]=>
  262. int(0)
  263. }
  264. --uppercase TRUE--
  265. array(11) {
  266. ["seconds"]=>
  267. int(1)
  268. ["minutes"]=>
  269. int(30)
  270. ["hours"]=>
  271. int(5)
  272. ["mday"]=>
  273. int(1)
  274. ["wday"]=>
  275. int(4)
  276. ["mon"]=>
  277. int(1)
  278. ["year"]=>
  279. int(1970)
  280. ["yday"]=>
  281. int(0)
  282. ["weekday"]=>
  283. string(8) "Thursday"
  284. ["month"]=>
  285. string(7) "January"
  286. [0]=>
  287. int(1)
  288. }
  289. --uppercase FALSE--
  290. array(11) {
  291. ["seconds"]=>
  292. int(0)
  293. ["minutes"]=>
  294. int(30)
  295. ["hours"]=>
  296. int(5)
  297. ["mday"]=>
  298. int(1)
  299. ["wday"]=>
  300. int(4)
  301. ["mon"]=>
  302. int(1)
  303. ["year"]=>
  304. int(1970)
  305. ["yday"]=>
  306. int(0)
  307. ["weekday"]=>
  308. string(8) "Thursday"
  309. ["month"]=>
  310. string(7) "January"
  311. [0]=>
  312. int(0)
  313. }
  314. --empty string DQ--
  315. Warning: getdate() expects parameter 1 to be long, string given in %s on line %d
  316. bool(false)
  317. --empty string SQ--
  318. Warning: getdate() expects parameter 1 to be long, string given in %s on line %d
  319. bool(false)
  320. --string DQ--
  321. Warning: getdate() expects parameter 1 to be long, string given in %s on line %d
  322. bool(false)
  323. --string SQ--
  324. Warning: getdate() expects parameter 1 to be long, string given in %s on line %d
  325. bool(false)
  326. --mixed case string--
  327. Warning: getdate() expects parameter 1 to be long, string given in %s on line %d
  328. bool(false)
  329. --heredoc--
  330. Warning: getdate() expects parameter 1 to be long, string given in %s on line %d
  331. bool(false)
  332. --instance of classWithToString--
  333. Warning: getdate() expects parameter 1 to be long, object given in %s on line %d
  334. bool(false)
  335. --instance of classWithoutToString--
  336. Warning: getdate() expects parameter 1 to be long, object given in %s on line %d
  337. bool(false)
  338. --undefined var--
  339. array(11) {
  340. ["seconds"]=>
  341. int(0)
  342. ["minutes"]=>
  343. int(30)
  344. ["hours"]=>
  345. int(5)
  346. ["mday"]=>
  347. int(1)
  348. ["wday"]=>
  349. int(4)
  350. ["mon"]=>
  351. int(1)
  352. ["year"]=>
  353. int(1970)
  354. ["yday"]=>
  355. int(0)
  356. ["weekday"]=>
  357. string(8) "Thursday"
  358. ["month"]=>
  359. string(7) "January"
  360. [0]=>
  361. int(0)
  362. }
  363. --unset var--
  364. array(11) {
  365. ["seconds"]=>
  366. int(0)
  367. ["minutes"]=>
  368. int(30)
  369. ["hours"]=>
  370. int(5)
  371. ["mday"]=>
  372. int(1)
  373. ["wday"]=>
  374. int(4)
  375. ["mon"]=>
  376. int(1)
  377. ["year"]=>
  378. int(1970)
  379. ["yday"]=>
  380. int(0)
  381. ["weekday"]=>
  382. string(8) "Thursday"
  383. ["month"]=>
  384. string(7) "January"
  385. [0]=>
  386. int(0)
  387. }
  388. ===DONE===