mktime_variation6.phpt 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. --TEST--
  2. Test mktime() function : usage variation - Passing unexpected values to sixth argument $year.
  3. --FILE--
  4. <?php
  5. /* Prototype : int mktime ([ int $hour= date("H") [, int $minute= date("i") [, int $second= date("s") [, int $month= date("n") [, int $day= date("j") [, int $year= date("Y") [, int $is_dst= -1 ]]]]]]] )
  6. * Description: Get Unix timestamp for a date
  7. * Source code: ext/date/php_date.c
  8. * Alias to functions:
  9. */
  10. echo "*** Testing mktime() : usage variation - unexpected values to sixth argument \$year***\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 12345' => 12345,
  40. 'int -12345' => -12345,
  41. // float data
  42. 'float 10.5' => 10.5,
  43. 'float -10.5' => -10.5,
  44. 'float .5' => .5,
  45. // array data
  46. 'empty array' => array(),
  47. 'int indexed array' => $index_array,
  48. 'associative array' => $assoc_array,
  49. 'nested arrays' => array('foo', $index_array, $assoc_array),
  50. // null data
  51. 'uppercase NULL' => NULL,
  52. 'lowercase null' => null,
  53. // boolean data
  54. 'lowercase true' => true,
  55. 'lowercase false' =>false,
  56. 'uppercase TRUE' =>TRUE,
  57. 'uppercase FALSE' =>FALSE,
  58. // empty data
  59. 'empty string DQ' => "",
  60. 'empty string SQ' => '',
  61. // string data
  62. 'string DQ' => "string",
  63. 'string SQ' => 'string',
  64. 'mixed case string' => "sTrInG",
  65. 'heredoc' => $heredoc,
  66. // object data
  67. 'instance of classWithToString' => new classWithToString(),
  68. 'instance of classWithoutToString' => new classWithoutToString(),
  69. // undefined data
  70. 'undefined var' => @$undefined_var,
  71. // unset data
  72. 'unset var' => @$unset_var,
  73. // resource
  74. 'resource' => $file_handle
  75. );
  76. $hour = 10;
  77. $minute = 30;
  78. $second = 45;
  79. $month = 7;
  80. $day = 2;
  81. foreach($inputs as $variation =>$year) {
  82. echo "\n-- $variation --\n";
  83. var_dump( mktime($hour, $minute, $second, $month, $day, $year) );
  84. };
  85. // closing the resource
  86. fclose( $file_handle );
  87. ?>
  88. ===DONE===
  89. --EXPECTF--
  90. *** Testing mktime() : usage variation - unexpected values to sixth argument $year***
  91. -- int 0 --
  92. int(%i)
  93. -- int 12345 --
  94. %rint\(-?[1-9][0-9]*\)|bool\(false\)%r
  95. -- int -12345 --
  96. %rint\(-?[1-9][0-9]*\)|bool\(false\)%r
  97. -- float 10.5 --
  98. int(%i)
  99. -- float -10.5 --
  100. %rint\(-?[1-9][0-9]*\)|bool\(false\)%r
  101. -- float .5 --
  102. int(%i)
  103. -- empty array --
  104. Warning: mktime() expects parameter 6 to be long, array given in %s on line %d
  105. bool(false)
  106. -- int indexed array --
  107. Warning: mktime() expects parameter 6 to be long, array given in %s on line %d
  108. bool(false)
  109. -- associative array --
  110. Warning: mktime() expects parameter 6 to be long, array given in %s on line %d
  111. bool(false)
  112. -- nested arrays --
  113. Warning: mktime() expects parameter 6 to be long, array given in %s on line %d
  114. bool(false)
  115. -- uppercase NULL --
  116. int(%i)
  117. -- lowercase null --
  118. int(%i)
  119. -- lowercase true --
  120. int(%i)
  121. -- lowercase false --
  122. int(%i)
  123. -- uppercase TRUE --
  124. int(%i)
  125. -- uppercase FALSE --
  126. int(%i)
  127. -- empty string DQ --
  128. Warning: mktime() expects parameter 6 to be long, string given in %s on line %d
  129. bool(false)
  130. -- empty string SQ --
  131. Warning: mktime() expects parameter 6 to be long, string given in %s on line %d
  132. bool(false)
  133. -- string DQ --
  134. Warning: mktime() expects parameter 6 to be long, string given in %s on line %d
  135. bool(false)
  136. -- string SQ --
  137. Warning: mktime() expects parameter 6 to be long, string given in %s on line %d
  138. bool(false)
  139. -- mixed case string --
  140. Warning: mktime() expects parameter 6 to be long, string given in %s on line %d
  141. bool(false)
  142. -- heredoc --
  143. Warning: mktime() expects parameter 6 to be long, string given in %s on line %d
  144. bool(false)
  145. -- instance of classWithToString --
  146. Warning: mktime() expects parameter 6 to be long, object given in %s on line %d
  147. bool(false)
  148. -- instance of classWithoutToString --
  149. Warning: mktime() expects parameter 6 to be long, object given in %s on line %d
  150. bool(false)
  151. -- undefined var --
  152. int(%i)
  153. -- unset var --
  154. int(%i)
  155. -- resource --
  156. Warning: mktime() expects parameter 6 to be long, resource given in %s on line %d
  157. bool(false)
  158. ===DONE===