localtime_variation2.phpt 8.4 KB

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