localtime_variation1.phpt 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. --TEST--
  2. Test localtime() function : usage variation - Passing unexpected values to first argument 'timestamp'.
  3. --FILE--
  4. <?php
  5. /* Prototype : array localtime([int timestamp [, bool associative_array]])
  6. * Description: Returns the results of the C system call localtime as an associative array
  7. * if the associative_array argument is set to 1 other wise it is a regular array
  8. * Source code: ext/date/php_date.c
  9. * Alias to functions:
  10. */
  11. echo "*** Testing localtime() : usage variation ***\n";
  12. date_default_timezone_set("UTC");
  13. // Initialise function arguments not being substituted (if any)
  14. $is_associative = true;
  15. //get an unset variable
  16. $unset_var = 10;
  17. unset ($unset_var);
  18. // define some classes
  19. class classWithToString
  20. {
  21. public function __toString() {
  22. return "Class A object";
  23. }
  24. }
  25. class classWithoutToString
  26. {
  27. }
  28. // heredoc string
  29. $heredoc = <<<EOT
  30. hello world
  31. EOT;
  32. // add arrays
  33. $index_array = array (1, 2, 3);
  34. $assoc_array = array ('one' => 1, 'two' => 2);
  35. //array of values to iterate over
  36. $inputs = array(
  37. // float data
  38. 'float 10.5' => 10.5,
  39. 'float -10.5' => -10.5,
  40. 'float .5' => .5,
  41. // array data
  42. 'empty array' => array(),
  43. 'int indexed array' => $index_array,
  44. 'associative array' => $assoc_array,
  45. 'nested arrays' => array('foo', $index_array, $assoc_array),
  46. // null data
  47. 'uppercase NULL' => NULL,
  48. 'lowercase null' => null,
  49. // boolean data
  50. 'lowercase true' => true,
  51. 'lowercase false' =>false,
  52. 'uppercase TRUE' =>TRUE,
  53. 'uppercase FALSE' =>FALSE,
  54. // empty data
  55. 'empty string DQ' => "",
  56. 'empty string SQ' => '',
  57. // string data
  58. 'string DQ' => "string",
  59. 'string SQ' => 'string',
  60. 'mixed case string' => "sTrInG",
  61. 'heredoc' => $heredoc,
  62. // object data
  63. 'instance of classWithToString' => new classWithToString(),
  64. 'instance of classWithoutToString' => new classWithoutToString(),
  65. // undefined data
  66. 'undefined var' => @$undefined_var,
  67. // unset data
  68. 'unset var' => @$unset_var,
  69. );
  70. // loop through each element of the array for timestamp
  71. foreach($inputs as $key =>$value) {
  72. echo "\n--$key--\n";
  73. var_dump( localtime($value) );
  74. var_dump( localtime($value, $is_associative) );
  75. };
  76. ?>
  77. ===DONE===
  78. --EXPECTF--
  79. *** Testing localtime() : usage variation ***
  80. --float 10.5--
  81. array(9) {
  82. [0]=>
  83. int(10)
  84. [1]=>
  85. int(0)
  86. [2]=>
  87. int(0)
  88. [3]=>
  89. int(1)
  90. [4]=>
  91. int(0)
  92. [5]=>
  93. int(70)
  94. [6]=>
  95. int(4)
  96. [7]=>
  97. int(0)
  98. [8]=>
  99. int(0)
  100. }
  101. array(9) {
  102. ["tm_sec"]=>
  103. int(10)
  104. ["tm_min"]=>
  105. int(0)
  106. ["tm_hour"]=>
  107. int(0)
  108. ["tm_mday"]=>
  109. int(1)
  110. ["tm_mon"]=>
  111. int(0)
  112. ["tm_year"]=>
  113. int(70)
  114. ["tm_wday"]=>
  115. int(4)
  116. ["tm_yday"]=>
  117. int(0)
  118. ["tm_isdst"]=>
  119. int(0)
  120. }
  121. --float -10.5--
  122. array(9) {
  123. [0]=>
  124. int(50)
  125. [1]=>
  126. int(59)
  127. [2]=>
  128. int(23)
  129. [3]=>
  130. int(31)
  131. [4]=>
  132. int(11)
  133. [5]=>
  134. int(69)
  135. [6]=>
  136. int(3)
  137. [7]=>
  138. int(364)
  139. [8]=>
  140. int(0)
  141. }
  142. array(9) {
  143. ["tm_sec"]=>
  144. int(50)
  145. ["tm_min"]=>
  146. int(59)
  147. ["tm_hour"]=>
  148. int(23)
  149. ["tm_mday"]=>
  150. int(31)
  151. ["tm_mon"]=>
  152. int(11)
  153. ["tm_year"]=>
  154. int(69)
  155. ["tm_wday"]=>
  156. int(3)
  157. ["tm_yday"]=>
  158. int(364)
  159. ["tm_isdst"]=>
  160. int(0)
  161. }
  162. --float .5--
  163. array(9) {
  164. [0]=>
  165. int(0)
  166. [1]=>
  167. int(0)
  168. [2]=>
  169. int(0)
  170. [3]=>
  171. int(1)
  172. [4]=>
  173. int(0)
  174. [5]=>
  175. int(70)
  176. [6]=>
  177. int(4)
  178. [7]=>
  179. int(0)
  180. [8]=>
  181. int(0)
  182. }
  183. array(9) {
  184. ["tm_sec"]=>
  185. int(0)
  186. ["tm_min"]=>
  187. int(0)
  188. ["tm_hour"]=>
  189. int(0)
  190. ["tm_mday"]=>
  191. int(1)
  192. ["tm_mon"]=>
  193. int(0)
  194. ["tm_year"]=>
  195. int(70)
  196. ["tm_wday"]=>
  197. int(4)
  198. ["tm_yday"]=>
  199. int(0)
  200. ["tm_isdst"]=>
  201. int(0)
  202. }
  203. --empty array--
  204. Warning: localtime() expects parameter 1 to be long, array given in %s on line %d
  205. bool(false)
  206. Warning: localtime() expects parameter 1 to be long, array given in %s on line %d
  207. bool(false)
  208. --int indexed array--
  209. Warning: localtime() expects parameter 1 to be long, array given in %s on line %d
  210. bool(false)
  211. Warning: localtime() expects parameter 1 to be long, array given in %s on line %d
  212. bool(false)
  213. --associative array--
  214. Warning: localtime() expects parameter 1 to be long, array given in %s on line %d
  215. bool(false)
  216. Warning: localtime() expects parameter 1 to be long, array given in %s on line %d
  217. bool(false)
  218. --nested arrays--
  219. Warning: localtime() expects parameter 1 to be long, array given in %s on line %d
  220. bool(false)
  221. Warning: localtime() expects parameter 1 to be long, array given in %s on line %d
  222. bool(false)
  223. --uppercase NULL--
  224. array(9) {
  225. [0]=>
  226. int(0)
  227. [1]=>
  228. int(0)
  229. [2]=>
  230. int(0)
  231. [3]=>
  232. int(1)
  233. [4]=>
  234. int(0)
  235. [5]=>
  236. int(70)
  237. [6]=>
  238. int(4)
  239. [7]=>
  240. int(0)
  241. [8]=>
  242. int(0)
  243. }
  244. array(9) {
  245. ["tm_sec"]=>
  246. int(0)
  247. ["tm_min"]=>
  248. int(0)
  249. ["tm_hour"]=>
  250. int(0)
  251. ["tm_mday"]=>
  252. int(1)
  253. ["tm_mon"]=>
  254. int(0)
  255. ["tm_year"]=>
  256. int(70)
  257. ["tm_wday"]=>
  258. int(4)
  259. ["tm_yday"]=>
  260. int(0)
  261. ["tm_isdst"]=>
  262. int(0)
  263. }
  264. --lowercase null--
  265. array(9) {
  266. [0]=>
  267. int(0)
  268. [1]=>
  269. int(0)
  270. [2]=>
  271. int(0)
  272. [3]=>
  273. int(1)
  274. [4]=>
  275. int(0)
  276. [5]=>
  277. int(70)
  278. [6]=>
  279. int(4)
  280. [7]=>
  281. int(0)
  282. [8]=>
  283. int(0)
  284. }
  285. array(9) {
  286. ["tm_sec"]=>
  287. int(0)
  288. ["tm_min"]=>
  289. int(0)
  290. ["tm_hour"]=>
  291. int(0)
  292. ["tm_mday"]=>
  293. int(1)
  294. ["tm_mon"]=>
  295. int(0)
  296. ["tm_year"]=>
  297. int(70)
  298. ["tm_wday"]=>
  299. int(4)
  300. ["tm_yday"]=>
  301. int(0)
  302. ["tm_isdst"]=>
  303. int(0)
  304. }
  305. --lowercase true--
  306. array(9) {
  307. [0]=>
  308. int(1)
  309. [1]=>
  310. int(0)
  311. [2]=>
  312. int(0)
  313. [3]=>
  314. int(1)
  315. [4]=>
  316. int(0)
  317. [5]=>
  318. int(70)
  319. [6]=>
  320. int(4)
  321. [7]=>
  322. int(0)
  323. [8]=>
  324. int(0)
  325. }
  326. array(9) {
  327. ["tm_sec"]=>
  328. int(1)
  329. ["tm_min"]=>
  330. int(0)
  331. ["tm_hour"]=>
  332. int(0)
  333. ["tm_mday"]=>
  334. int(1)
  335. ["tm_mon"]=>
  336. int(0)
  337. ["tm_year"]=>
  338. int(70)
  339. ["tm_wday"]=>
  340. int(4)
  341. ["tm_yday"]=>
  342. int(0)
  343. ["tm_isdst"]=>
  344. int(0)
  345. }
  346. --lowercase false--
  347. array(9) {
  348. [0]=>
  349. int(0)
  350. [1]=>
  351. int(0)
  352. [2]=>
  353. int(0)
  354. [3]=>
  355. int(1)
  356. [4]=>
  357. int(0)
  358. [5]=>
  359. int(70)
  360. [6]=>
  361. int(4)
  362. [7]=>
  363. int(0)
  364. [8]=>
  365. int(0)
  366. }
  367. array(9) {
  368. ["tm_sec"]=>
  369. int(0)
  370. ["tm_min"]=>
  371. int(0)
  372. ["tm_hour"]=>
  373. int(0)
  374. ["tm_mday"]=>
  375. int(1)
  376. ["tm_mon"]=>
  377. int(0)
  378. ["tm_year"]=>
  379. int(70)
  380. ["tm_wday"]=>
  381. int(4)
  382. ["tm_yday"]=>
  383. int(0)
  384. ["tm_isdst"]=>
  385. int(0)
  386. }
  387. --uppercase TRUE--
  388. array(9) {
  389. [0]=>
  390. int(1)
  391. [1]=>
  392. int(0)
  393. [2]=>
  394. int(0)
  395. [3]=>
  396. int(1)
  397. [4]=>
  398. int(0)
  399. [5]=>
  400. int(70)
  401. [6]=>
  402. int(4)
  403. [7]=>
  404. int(0)
  405. [8]=>
  406. int(0)
  407. }
  408. array(9) {
  409. ["tm_sec"]=>
  410. int(1)
  411. ["tm_min"]=>
  412. int(0)
  413. ["tm_hour"]=>
  414. int(0)
  415. ["tm_mday"]=>
  416. int(1)
  417. ["tm_mon"]=>
  418. int(0)
  419. ["tm_year"]=>
  420. int(70)
  421. ["tm_wday"]=>
  422. int(4)
  423. ["tm_yday"]=>
  424. int(0)
  425. ["tm_isdst"]=>
  426. int(0)
  427. }
  428. --uppercase FALSE--
  429. array(9) {
  430. [0]=>
  431. int(0)
  432. [1]=>
  433. int(0)
  434. [2]=>
  435. int(0)
  436. [3]=>
  437. int(1)
  438. [4]=>
  439. int(0)
  440. [5]=>
  441. int(70)
  442. [6]=>
  443. int(4)
  444. [7]=>
  445. int(0)
  446. [8]=>
  447. int(0)
  448. }
  449. array(9) {
  450. ["tm_sec"]=>
  451. int(0)
  452. ["tm_min"]=>
  453. int(0)
  454. ["tm_hour"]=>
  455. int(0)
  456. ["tm_mday"]=>
  457. int(1)
  458. ["tm_mon"]=>
  459. int(0)
  460. ["tm_year"]=>
  461. int(70)
  462. ["tm_wday"]=>
  463. int(4)
  464. ["tm_yday"]=>
  465. int(0)
  466. ["tm_isdst"]=>
  467. int(0)
  468. }
  469. --empty string DQ--
  470. Warning: localtime() expects parameter 1 to be long, string given in %s on line %d
  471. bool(false)
  472. Warning: localtime() expects parameter 1 to be long, string given in %s on line %d
  473. bool(false)
  474. --empty string SQ--
  475. Warning: localtime() expects parameter 1 to be long, string given in %s on line %d
  476. bool(false)
  477. Warning: localtime() expects parameter 1 to be long, string given in %s on line %d
  478. bool(false)
  479. --string DQ--
  480. Warning: localtime() expects parameter 1 to be long, string given in %s on line %d
  481. bool(false)
  482. Warning: localtime() expects parameter 1 to be long, string given in %s on line %d
  483. bool(false)
  484. --string SQ--
  485. Warning: localtime() expects parameter 1 to be long, string given in %s on line %d
  486. bool(false)
  487. Warning: localtime() expects parameter 1 to be long, string given in %s on line %d
  488. bool(false)
  489. --mixed case string--
  490. Warning: localtime() expects parameter 1 to be long, string given in %s on line %d
  491. bool(false)
  492. Warning: localtime() expects parameter 1 to be long, string given in %s on line %d
  493. bool(false)
  494. --heredoc--
  495. Warning: localtime() expects parameter 1 to be long, string given in %s on line %d
  496. bool(false)
  497. Warning: localtime() expects parameter 1 to be long, string given in %s on line %d
  498. bool(false)
  499. --instance of classWithToString--
  500. Warning: localtime() expects parameter 1 to be long, object given in %s on line %d
  501. bool(false)
  502. Warning: localtime() expects parameter 1 to be long, object given in %s on line %d
  503. bool(false)
  504. --instance of classWithoutToString--
  505. Warning: localtime() expects parameter 1 to be long, object given in %s on line %d
  506. bool(false)
  507. Warning: localtime() expects parameter 1 to be long, object given in %s on line %d
  508. bool(false)
  509. --undefined var--
  510. array(9) {
  511. [0]=>
  512. int(0)
  513. [1]=>
  514. int(0)
  515. [2]=>
  516. int(0)
  517. [3]=>
  518. int(1)
  519. [4]=>
  520. int(0)
  521. [5]=>
  522. int(70)
  523. [6]=>
  524. int(4)
  525. [7]=>
  526. int(0)
  527. [8]=>
  528. int(0)
  529. }
  530. array(9) {
  531. ["tm_sec"]=>
  532. int(0)
  533. ["tm_min"]=>
  534. int(0)
  535. ["tm_hour"]=>
  536. int(0)
  537. ["tm_mday"]=>
  538. int(1)
  539. ["tm_mon"]=>
  540. int(0)
  541. ["tm_year"]=>
  542. int(70)
  543. ["tm_wday"]=>
  544. int(4)
  545. ["tm_yday"]=>
  546. int(0)
  547. ["tm_isdst"]=>
  548. int(0)
  549. }
  550. --unset var--
  551. array(9) {
  552. [0]=>
  553. int(0)
  554. [1]=>
  555. int(0)
  556. [2]=>
  557. int(0)
  558. [3]=>
  559. int(1)
  560. [4]=>
  561. int(0)
  562. [5]=>
  563. int(70)
  564. [6]=>
  565. int(4)
  566. [7]=>
  567. int(0)
  568. [8]=>
  569. int(0)
  570. }
  571. array(9) {
  572. ["tm_sec"]=>
  573. int(0)
  574. ["tm_min"]=>
  575. int(0)
  576. ["tm_hour"]=>
  577. int(0)
  578. ["tm_mday"]=>
  579. int(1)
  580. ["tm_mon"]=>
  581. int(0)
  582. ["tm_year"]=>
  583. int(70)
  584. ["tm_wday"]=>
  585. int(4)
  586. ["tm_yday"]=>
  587. int(0)
  588. ["tm_isdst"]=>
  589. int(0)
  590. }
  591. ===DONE===