idate_variation2.phpt 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. --TEST--
  2. Test idate() function : usage variation - Passing unexpected values to second optional argument 'timestamp'.
  3. --FILE--
  4. <?php
  5. /* Prototype : int idate(string format [, int timestamp])
  6. * Description: Format a local time/date as integer
  7. * Source code: ext/date/php_date.c
  8. * Alias to functions:
  9. */
  10. echo "*** Testing idate() : usage variation ***\n";
  11. // Initialise function arguments not being substituted (if any)
  12. $format = 'Y';
  13. date_default_timezone_set("Asia/Calcutta");
  14. //get an unset variable
  15. $unset_var = 10;
  16. unset ($unset_var);
  17. // define some classes
  18. class classWithToString
  19. {
  20. public function __toString() {
  21. return "Class A object";
  22. }
  23. }
  24. class classWithoutToString
  25. {
  26. }
  27. // heredoc string
  28. $heredoc = <<<EOT
  29. hello world
  30. EOT;
  31. // add arrays
  32. $index_array = array (1, 2, 3);
  33. $assoc_array = array ('one' => 1, 'two' => 2);
  34. //array of values to iterate over
  35. $inputs = array(
  36. // float data
  37. 'float 10.5' => 10.5,
  38. 'float -10.5' => -10.5,
  39. 'float .5' => .5,
  40. // array data
  41. 'empty array' => array(),
  42. 'int indexed array' => $index_array,
  43. 'associative array' => $assoc_array,
  44. 'nested arrays' => array('foo', $index_array, $assoc_array),
  45. // null data
  46. 'uppercase NULL' => NULL,
  47. 'lowercase null' => null,
  48. // boolean data
  49. 'lowercase true' => true,
  50. 'lowercase false' =>false,
  51. 'uppercase TRUE' =>TRUE,
  52. 'uppercase FALSE' =>FALSE,
  53. // empty data
  54. 'empty string DQ' => "",
  55. 'empty string SQ' => '',
  56. // string data
  57. 'string DQ' => "string",
  58. 'string SQ' => 'string',
  59. 'mixed case string' => "sTrInG",
  60. 'heredoc' => $heredoc,
  61. // object data
  62. 'instance of classWithToString' => new classWithToString(),
  63. 'instance of classWithoutToString' => new classWithoutToString(),
  64. // undefined data
  65. 'undefined var' => @$undefined_var,
  66. // unset data
  67. 'unset var' => @$unset_var,
  68. );
  69. // loop through each element of the array for timestamp
  70. foreach($inputs as $key =>$value) {
  71. echo "\n--$key--\n";
  72. var_dump( idate($format, $value) );
  73. };
  74. ?>
  75. ===DONE===
  76. --EXPECTF--
  77. *** Testing idate() : usage variation ***
  78. --float 10.5--
  79. int(1970)
  80. --float -10.5--
  81. int(1970)
  82. --float .5--
  83. int(1970)
  84. --empty array--
  85. Warning: idate() expects parameter 2 to be long, array given in %s on line %d
  86. bool(false)
  87. --int indexed array--
  88. Warning: idate() expects parameter 2 to be long, array given in %s on line %d
  89. bool(false)
  90. --associative array--
  91. Warning: idate() expects parameter 2 to be long, array given in %s on line %d
  92. bool(false)
  93. --nested arrays--
  94. Warning: idate() expects parameter 2 to be long, array given in %s on line %d
  95. bool(false)
  96. --uppercase NULL--
  97. int(1970)
  98. --lowercase null--
  99. int(1970)
  100. --lowercase true--
  101. int(1970)
  102. --lowercase false--
  103. int(1970)
  104. --uppercase TRUE--
  105. int(1970)
  106. --uppercase FALSE--
  107. int(1970)
  108. --empty string DQ--
  109. Warning: idate() expects parameter 2 to be long, string given in %s on line %d
  110. bool(false)
  111. --empty string SQ--
  112. Warning: idate() expects parameter 2 to be long, string given in %s on line %d
  113. bool(false)
  114. --string DQ--
  115. Warning: idate() expects parameter 2 to be long, string given in %s on line %d
  116. bool(false)
  117. --string SQ--
  118. Warning: idate() expects parameter 2 to be long, string given in %s on line %d
  119. bool(false)
  120. --mixed case string--
  121. Warning: idate() expects parameter 2 to be long, string given in %s on line %d
  122. bool(false)
  123. --heredoc--
  124. Warning: idate() expects parameter 2 to be long, string given in %s on line %d
  125. bool(false)
  126. --instance of classWithToString--
  127. Warning: idate() expects parameter 2 to be long, object given in %s on line %d
  128. bool(false)
  129. --instance of classWithoutToString--
  130. Warning: idate() expects parameter 2 to be long, object given in %s on line %d
  131. bool(false)
  132. --undefined var--
  133. int(1970)
  134. --unset var--
  135. int(1970)
  136. ===DONE===