mktime_variation3.phpt 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. --TEST--
  2. Test mktime() function : usage variation - Passing unexpected values to third argument $second.
  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 third argument \$second***\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. foreach($inputs as $variation =>$second) {
  79. echo "\n-- $variation --\n";
  80. var_dump( mktime($hour, $minute, $second) );
  81. };
  82. // closing the resource
  83. fclose( $file_handle );
  84. ?>
  85. ===DONE===
  86. --EXPECTF--
  87. *** Testing mktime() : usage variation - unexpected values to third argument $second***
  88. -- int 0 --
  89. int(%i)
  90. -- int 12345 --
  91. int(%i)
  92. -- int -12345 --
  93. int(%i)
  94. -- float 10.5 --
  95. int(%i)
  96. -- float -10.5 --
  97. int(%i)
  98. -- float .5 --
  99. int(%i)
  100. -- empty array --
  101. Warning: mktime() expects parameter 3 to be long, array given in %s on line %d
  102. bool(false)
  103. -- int indexed array --
  104. Warning: mktime() expects parameter 3 to be long, array given in %s on line %d
  105. bool(false)
  106. -- associative array --
  107. Warning: mktime() expects parameter 3 to be long, array given in %s on line %d
  108. bool(false)
  109. -- nested arrays --
  110. Warning: mktime() expects parameter 3 to be long, array given in %s on line %d
  111. bool(false)
  112. -- uppercase NULL --
  113. int(%i)
  114. -- lowercase null --
  115. int(%i)
  116. -- lowercase true --
  117. int(%i)
  118. -- lowercase false --
  119. int(%i)
  120. -- uppercase TRUE --
  121. int(%i)
  122. -- uppercase FALSE --
  123. int(%i)
  124. -- empty string DQ --
  125. Warning: mktime() expects parameter 3 to be long, string given in %s on line %d
  126. bool(false)
  127. -- empty string SQ --
  128. Warning: mktime() expects parameter 3 to be long, string given in %s on line %d
  129. bool(false)
  130. -- string DQ --
  131. Warning: mktime() expects parameter 3 to be long, string given in %s on line %d
  132. bool(false)
  133. -- string SQ --
  134. Warning: mktime() expects parameter 3 to be long, string given in %s on line %d
  135. bool(false)
  136. -- mixed case string --
  137. Warning: mktime() expects parameter 3 to be long, string given in %s on line %d
  138. bool(false)
  139. -- heredoc --
  140. Warning: mktime() expects parameter 3 to be long, string given in %s on line %d
  141. bool(false)
  142. -- instance of classWithToString --
  143. Warning: mktime() expects parameter 3 to be long, object given in %s on line %d
  144. bool(false)
  145. -- instance of classWithoutToString --
  146. Warning: mktime() expects parameter 3 to be long, object given in %s on line %d
  147. bool(false)
  148. -- undefined var --
  149. int(%i)
  150. -- unset var --
  151. int(%i)
  152. -- resource --
  153. Warning: mktime() expects parameter 3 to be long, resource given in %s on line %d
  154. bool(false)
  155. ===DONE===