date_create_variation1.phpt 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. --TEST--
  2. Test date_create() function : usage variation - Passing unexpected values to first argument $time.
  3. --FILE--
  4. <?php
  5. /* Prototype : DateTime date_create ([ string $time [, DateTimeZone $timezone ]] )
  6. * Description: Returns new DateTime object
  7. * Source code: ext/date/php_date.c
  8. * Alias to functions: DateTime::__construct
  9. */
  10. echo "*** Testing date_create() : usage variation - unexpected values to first argument \$time***\n";
  11. //Set the default time zone
  12. date_default_timezone_set("Europe/London");
  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. // resource
  34. $file_handle = fopen(__FILE__, 'r');
  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' => -12345,
  42. // float data
  43. 'float 10.5' => 10.5,
  44. 'float -10.5' => -10.5,
  45. 'float .5' => .5,
  46. // array data
  47. 'empty array' => array(),
  48. 'int indexed array' => $index_array,
  49. 'associative array' => $assoc_array,
  50. 'nested arrays' => array('foo', $index_array, $assoc_array),
  51. // null data
  52. 'uppercase NULL' => NULL,
  53. 'lowercase null' => null,
  54. // boolean data
  55. 'lowercase true' => true,
  56. 'lowercase false' =>false,
  57. 'uppercase TRUE' =>TRUE,
  58. 'uppercase FALSE' =>FALSE,
  59. // empty data
  60. 'empty string DQ' => "",
  61. 'empty string SQ' => '',
  62. // string data
  63. 'string DQ' => "string",
  64. 'string SQ' => 'string',
  65. 'mixed case string' => "sTrInG",
  66. 'heredoc' => $heredoc,
  67. // object data
  68. 'instance of classWithToString' => new classWithToString(),
  69. 'instance of classWithoutToString' => new classWithoutToString(),
  70. // undefined data
  71. 'undefined var' => @$undefined_var,
  72. // unset data
  73. 'unset var' => @$unset_var,
  74. // resource
  75. 'resource' => $file_handle
  76. );
  77. $timezone = new DateTimeZone("Europe/London");
  78. foreach($inputs as $variation =>$time) {
  79. echo "\n-- $variation --\n";
  80. var_dump( date_create($time) );
  81. var_dump( date_create($time, $timezone) );
  82. };
  83. // closing the resource
  84. fclose( $file_handle);
  85. ?>
  86. ===DONE===
  87. --EXPECTF--
  88. *** Testing date_create() : usage variation - unexpected values to first argument $time***
  89. -- int 0 --
  90. bool(false)
  91. bool(false)
  92. -- int 1 --
  93. bool(false)
  94. bool(false)
  95. -- int 12345 --
  96. bool(false)
  97. bool(false)
  98. -- int -12345 --
  99. bool(false)
  100. bool(false)
  101. -- float 10.5 --
  102. object(DateTime)#%d (3) {
  103. ["date"]=>
  104. string(26) "%s"
  105. ["timezone_type"]=>
  106. int(3)
  107. ["timezone"]=>
  108. string(13) "Europe/London"
  109. }
  110. object(DateTime)#%d (3) {
  111. ["date"]=>
  112. string(26) "%s"
  113. ["timezone_type"]=>
  114. int(3)
  115. ["timezone"]=>
  116. string(13) "Europe/London"
  117. }
  118. -- float -10.5 --
  119. bool(false)
  120. bool(false)
  121. -- float .5 --
  122. object(DateTime)#%d (3) {
  123. ["date"]=>
  124. string(26) "%s"
  125. ["timezone_type"]=>
  126. int(3)
  127. ["timezone"]=>
  128. string(13) "Europe/London"
  129. }
  130. object(DateTime)#%d (3) {
  131. ["date"]=>
  132. string(26) "%s"
  133. ["timezone_type"]=>
  134. int(3)
  135. ["timezone"]=>
  136. string(13) "Europe/London"
  137. }
  138. -- empty array --
  139. Warning: date_create() expects parameter 1 to be string, array given in %s on line %d
  140. bool(false)
  141. Warning: date_create() expects parameter 1 to be string, array given in %s on line %d
  142. bool(false)
  143. -- int indexed array --
  144. Warning: date_create() expects parameter 1 to be string, array given in %s on line %d
  145. bool(false)
  146. Warning: date_create() expects parameter 1 to be string, array given in %s on line %d
  147. bool(false)
  148. -- associative array --
  149. Warning: date_create() expects parameter 1 to be string, array given in %s on line %d
  150. bool(false)
  151. Warning: date_create() expects parameter 1 to be string, array given in %s on line %d
  152. bool(false)
  153. -- nested arrays --
  154. Warning: date_create() expects parameter 1 to be string, array given in %s on line %d
  155. bool(false)
  156. Warning: date_create() expects parameter 1 to be string, array given in %s on line %d
  157. bool(false)
  158. -- uppercase NULL --
  159. object(DateTime)#%d (3) {
  160. ["date"]=>
  161. string(26) "%s"
  162. ["timezone_type"]=>
  163. int(3)
  164. ["timezone"]=>
  165. string(13) "Europe/London"
  166. }
  167. object(DateTime)#%d (3) {
  168. ["date"]=>
  169. string(26) "%s"
  170. ["timezone_type"]=>
  171. int(3)
  172. ["timezone"]=>
  173. string(13) "Europe/London"
  174. }
  175. -- lowercase null --
  176. object(DateTime)#%d (3) {
  177. ["date"]=>
  178. string(26) "%s"
  179. ["timezone_type"]=>
  180. int(3)
  181. ["timezone"]=>
  182. string(13) "Europe/London"
  183. }
  184. object(DateTime)#%d (3) {
  185. ["date"]=>
  186. string(26) "%s"
  187. ["timezone_type"]=>
  188. int(3)
  189. ["timezone"]=>
  190. string(13) "Europe/London"
  191. }
  192. -- lowercase true --
  193. bool(false)
  194. bool(false)
  195. -- lowercase false --
  196. object(DateTime)#%d (3) {
  197. ["date"]=>
  198. string(26) "%s"
  199. ["timezone_type"]=>
  200. int(3)
  201. ["timezone"]=>
  202. string(13) "Europe/London"
  203. }
  204. object(DateTime)#%d (3) {
  205. ["date"]=>
  206. string(26) "%s"
  207. ["timezone_type"]=>
  208. int(3)
  209. ["timezone"]=>
  210. string(13) "Europe/London"
  211. }
  212. -- uppercase TRUE --
  213. bool(false)
  214. bool(false)
  215. -- uppercase FALSE --
  216. object(DateTime)#%d (3) {
  217. ["date"]=>
  218. string(26) "%s"
  219. ["timezone_type"]=>
  220. int(3)
  221. ["timezone"]=>
  222. string(13) "Europe/London"
  223. }
  224. object(DateTime)#%d (3) {
  225. ["date"]=>
  226. string(26) "%s"
  227. ["timezone_type"]=>
  228. int(3)
  229. ["timezone"]=>
  230. string(13) "Europe/London"
  231. }
  232. -- empty string DQ --
  233. object(DateTime)#%d (3) {
  234. ["date"]=>
  235. string(26) "%s"
  236. ["timezone_type"]=>
  237. int(3)
  238. ["timezone"]=>
  239. string(13) "Europe/London"
  240. }
  241. object(DateTime)#%d (3) {
  242. ["date"]=>
  243. string(26) "%s"
  244. ["timezone_type"]=>
  245. int(3)
  246. ["timezone"]=>
  247. string(13) "Europe/London"
  248. }
  249. -- empty string SQ --
  250. object(DateTime)#%d (3) {
  251. ["date"]=>
  252. string(26) "%s"
  253. ["timezone_type"]=>
  254. int(3)
  255. ["timezone"]=>
  256. string(13) "Europe/London"
  257. }
  258. object(DateTime)#%d (3) {
  259. ["date"]=>
  260. string(26) "%s"
  261. ["timezone_type"]=>
  262. int(3)
  263. ["timezone"]=>
  264. string(13) "Europe/London"
  265. }
  266. -- string DQ --
  267. bool(false)
  268. bool(false)
  269. -- string SQ --
  270. bool(false)
  271. bool(false)
  272. -- mixed case string --
  273. bool(false)
  274. bool(false)
  275. -- heredoc --
  276. bool(false)
  277. bool(false)
  278. -- instance of classWithToString --
  279. bool(false)
  280. bool(false)
  281. -- instance of classWithoutToString --
  282. Warning: date_create() expects parameter 1 to be string, object given in %s on line %d
  283. bool(false)
  284. Warning: date_create() expects parameter 1 to be string, object given in %s on line %d
  285. bool(false)
  286. -- undefined var --
  287. object(DateTime)#%d (3) {
  288. ["date"]=>
  289. string(26) "%s"
  290. ["timezone_type"]=>
  291. int(3)
  292. ["timezone"]=>
  293. string(13) "Europe/London"
  294. }
  295. object(DateTime)#%d (3) {
  296. ["date"]=>
  297. string(26) "%s"
  298. ["timezone_type"]=>
  299. int(3)
  300. ["timezone"]=>
  301. string(13) "Europe/London"
  302. }
  303. -- unset var --
  304. object(DateTime)#%d (3) {
  305. ["date"]=>
  306. string(26) "%s"
  307. ["timezone_type"]=>
  308. int(3)
  309. ["timezone"]=>
  310. string(13) "Europe/London"
  311. }
  312. object(DateTime)#%d (3) {
  313. ["date"]=>
  314. string(26) "%s"
  315. ["timezone_type"]=>
  316. int(3)
  317. ["timezone"]=>
  318. string(13) "Europe/London"
  319. }
  320. -- resource --
  321. Warning: date_create() expects parameter 1 to be string, resource given in %s on line %d
  322. bool(false)
  323. Warning: date_create() expects parameter 1 to be string, resource given in %s on line %d
  324. bool(false)
  325. ===DONE===