2 Test DateTime::setTime() function : usage variation - Passing unexpected values to third argument $second.
5 /* Prototype : public DateTime DateTime::setTime ( int $hour , int $minute [, int $second ] )
6 * Description: Resets the current time of the DateTime object to a different time.
7 * Source code: ext/date/php_date.c
8 * Alias to functions: date_time_set
11 echo "*** Testing DateTime::setTime() : usage variation - unexpected values to third argument \$second***\n";
13 //Set the default time zone
14 date_default_timezone_set("Europe/London");
16 //get an unset variable
20 // define some classes
21 class classWithToString
23 public function __toString() {
24 return "Class A object";
28 class classWithoutToString
38 $index_array = array (1, 2, 3);
39 $assoc_array = array ('one' => 1, 'two' => 2);
42 $file_handle = fopen(__FILE__, 'r');
44 //array of values to iterate over
51 'int -12345' => -12345,
55 'float -10.5' => -10.5,
59 'empty array' => array(),
60 'int indexed array' => $index_array,
61 'associative array' => $assoc_array,
62 'nested arrays' => array('foo', $index_array, $assoc_array),
65 'uppercase NULL' => NULL,
66 'lowercase null' => null,
69 'lowercase true' => true,
70 'lowercase false' =>false,
71 'uppercase TRUE' =>TRUE,
72 'uppercase FALSE' =>FALSE,
75 'empty string DQ' => "",
76 'empty string SQ' => '',
79 'string DQ' => "string",
80 'string SQ' => 'string',
81 'mixed case string' => "sTrInG",
82 'heredoc' => $heredoc,
85 'instance of classWithToString' => new classWithToString(),
86 'instance of classWithoutToString' => new classWithoutToString(),
89 'undefined var' => @$undefined_var,
92 'unset var' => @$unset_var,
95 'resource' => $file_handle
98 $object = new DateTime("2009-01-31 15:14:10");
102 foreach($inputs as $variation =>$sec) {
103 echo "\n-- $variation --\n";
104 var_dump( $object->setTime($hour, $minute, $sec) );
107 // closing the resource
108 fclose( $file_handle );
113 *** Testing DateTime::setTime() : usage variation - unexpected values to third argument $second***
116 object(DateTime)#%d (3) {
118 string(19) "2009-01-31 10:13:00"
122 string(13) "Europe/London"
126 object(DateTime)#%d (3) {
128 string(19) "2009-01-31 10:13:01"
132 string(13) "Europe/London"
136 object(DateTime)#%d (3) {
138 string(19) "2009-01-31 13:38:45"
142 string(13) "Europe/London"
146 object(DateTime)#%d (3) {
148 string(19) "2009-01-31 06:47:15"
152 string(13) "Europe/London"
156 object(DateTime)#%d (3) {
158 string(19) "2009-01-31 10:13:10"
162 string(13) "Europe/London"
166 object(DateTime)#%d (3) {
168 string(19) "2009-01-31 10:12:50"
172 string(13) "Europe/London"
176 object(DateTime)#%d (3) {
178 string(19) "2009-01-31 10:13:00"
182 string(13) "Europe/London"
187 Warning: DateTime::setTime() expects parameter 3 to be long, array given in %s on line %d
190 -- int indexed array --
192 Warning: DateTime::setTime() expects parameter 3 to be long, array given in %s on line %d
195 -- associative array --
197 Warning: DateTime::setTime() expects parameter 3 to be long, array given in %s on line %d
202 Warning: DateTime::setTime() expects parameter 3 to be long, array given in %s on line %d
206 object(DateTime)#%d (3) {
208 string(19) "2009-01-31 10:13:00"
212 string(13) "Europe/London"
216 object(DateTime)#%d (3) {
218 string(19) "2009-01-31 10:13:00"
222 string(13) "Europe/London"
226 object(DateTime)#%d (3) {
228 string(19) "2009-01-31 10:13:01"
232 string(13) "Europe/London"
235 -- lowercase false --
236 object(DateTime)#%d (3) {
238 string(19) "2009-01-31 10:13:00"
242 string(13) "Europe/London"
246 object(DateTime)#%d (3) {
248 string(19) "2009-01-31 10:13:01"
252 string(13) "Europe/London"
255 -- uppercase FALSE --
256 object(DateTime)#%d (3) {
258 string(19) "2009-01-31 10:13:00"
262 string(13) "Europe/London"
265 -- empty string DQ --
267 Warning: DateTime::setTime() expects parameter 3 to be long, string given in %s on line %d
270 -- empty string SQ --
272 Warning: DateTime::setTime() expects parameter 3 to be long, string given in %s on line %d
277 Warning: DateTime::setTime() expects parameter 3 to be long, string given in %s on line %d
282 Warning: DateTime::setTime() expects parameter 3 to be long, string given in %s on line %d
285 -- mixed case string --
287 Warning: DateTime::setTime() expects parameter 3 to be long, string given in %s on line %d
292 Warning: DateTime::setTime() expects parameter 3 to be long, string given in %s on line %d
295 -- instance of classWithToString --
297 Warning: DateTime::setTime() expects parameter 3 to be long, object given in %s on line %d
300 -- instance of classWithoutToString --
302 Warning: DateTime::setTime() expects parameter 3 to be long, object given in %s on line %d
306 object(DateTime)#%d (3) {
308 string(19) "2009-01-31 10:13:00"
312 string(13) "Europe/London"
316 object(DateTime)#%d (3) {
318 string(19) "2009-01-31 10:13:00"
322 string(13) "Europe/London"
327 Warning: DateTime::setTime() expects parameter 3 to be long, resource given in %s on line %d