1--TEST-- 2Test date_sunset() function : usage variation - Passing unexpected values to first argument time. 3--FILE-- 4<?php 5/* Prototype : mixed date_sunset(mixed time [, int format [, float latitude [, float longitude [, float zenith [, float gmt_offset]]]]]) 6 * Description: Returns time of sunset for a given day and location 7 * Source code: ext/date/php_date.c 8 * Alias to functions: 9 */ 10 11echo "*** Testing date_sunset() : usage variation ***\n"; 12 13//Initialise the variables 14$latitude = 38.4; 15$longitude = -9; 16$zenith = 90; 17$gmt_offset = 1; 18date_default_timezone_set("Asia/Calcutta"); 19 20//get an unset variable 21$unset_var = 10; 22unset ($unset_var); 23 24// define some classes 25class classWithToString 26{ 27 public function __toString() { 28 return "Class A object"; 29 } 30} 31 32class classWithoutToString 33{ 34} 35 36// heredoc string 37$heredoc = <<<EOT 38hello world 39EOT; 40 41// add arrays 42$index_array = array (1, 2, 3); 43$assoc_array = array ('one' => 1, 'two' => 2); 44 45//array of values to iterate over 46$inputs = array( 47 48 // int data 49 'int 0' => 0, 50 'int 1' => 1, 51 'int 12345' => 12345, 52 'int -12345' => -2345, 53 54 // float data 55 'float 10.5' => 10.5, 56 'float -10.5' => -10.5, 57 'float .5' => .5, 58 59 // array data 60 'empty array' => array(), 61 'int indexed array' => $index_array, 62 'associative array' => $assoc_array, 63 'nested arrays' => array('foo', $index_array, $assoc_array), 64 65 // null data 66 'uppercase NULL' => NULL, 67 'lowercase null' => null, 68 69 // boolean data 70 'lowercase true' => true, 71 'lowercase false' =>false, 72 'uppercase TRUE' =>TRUE, 73 'uppercase FALSE' =>FALSE, 74 75 // empty data 76 'empty string DQ' => "", 77 'empty string SQ' => '', 78 79 // string data 80 'string DQ' => "string", 81 'string SQ' => 'string', 82 'mixed case string' => "sTrInG", 83 'heredoc' => $heredoc, 84 85 // object data 86 'instance of classWithToString' => new classWithToString(), 87 'instance of classWithoutToString' => new classWithoutToString(), 88 89 // undefined data 90 'undefined var' => @$undefined_var, 91 92 // unset data 93 'unset var' => @$unset_var, 94); 95 96// loop through each element of the array for time 97 98foreach($inputs as $key =>$value) { 99 echo "\n--$key--\n"; 100 var_dump( date_sunset($value, SUNFUNCS_RET_STRING, $latitude, $longitude, $zenith, $gmt_offset) ); 101 var_dump( date_sunset($value, SUNFUNCS_RET_DOUBLE, $latitude, $longitude, $zenith, $gmt_offset) ); 102 var_dump( date_sunset($value, SUNFUNCS_RET_TIMESTAMP, $latitude, $longitude, $zenith, $gmt_offset) ); 103}; 104 105?> 106===DONE=== 107--EXPECTF-- 108*** Testing date_sunset() : usage variation *** 109 110--int 0-- 111string(5) "18:22" 112float(18.377%d) 113int(62558) 114 115--int 1-- 116string(5) "18:22" 117float(18.377%d) 118int(62558) 119 120--int 12345-- 121string(5) "18:22" 122float(18.377%d) 123int(62558) 124 125--int -12345-- 126string(5) "18:22" 127float(18.377%d) 128int(62558) 129 130--float 10.5-- 131string(5) "18:22" 132float(18.377%d) 133int(62558) 134 135--float -10.5-- 136string(5) "18:22" 137float(18.377%d) 138int(62558) 139 140--float .5-- 141string(5) "18:22" 142float(18.377%d) 143int(62558) 144 145--empty array-- 146 147Warning: date_sunset() expects parameter 1 to be long, array given in %s on line %d 148bool(false) 149 150Warning: date_sunset() expects parameter 1 to be long, array given in %s on line %d 151bool(false) 152 153Warning: date_sunset() expects parameter 1 to be long, array given in %s on line %d 154bool(false) 155 156--int indexed array-- 157 158Warning: date_sunset() expects parameter 1 to be long, array given in %s on line %d 159bool(false) 160 161Warning: date_sunset() expects parameter 1 to be long, array given in %s on line %d 162bool(false) 163 164Warning: date_sunset() expects parameter 1 to be long, array given in %s on line %d 165bool(false) 166 167--associative array-- 168 169Warning: date_sunset() expects parameter 1 to be long, array given in %s on line %d 170bool(false) 171 172Warning: date_sunset() expects parameter 1 to be long, array given in %s on line %d 173bool(false) 174 175Warning: date_sunset() expects parameter 1 to be long, array given in %s on line %d 176bool(false) 177 178--nested arrays-- 179 180Warning: date_sunset() expects parameter 1 to be long, array given in %s on line %d 181bool(false) 182 183Warning: date_sunset() expects parameter 1 to be long, array given in %s on line %d 184bool(false) 185 186Warning: date_sunset() expects parameter 1 to be long, array given in %s on line %d 187bool(false) 188 189--uppercase NULL-- 190string(5) "18:22" 191float(18.377%d) 192int(62558) 193 194--lowercase null-- 195string(5) "18:22" 196float(18.377%d) 197int(62558) 198 199--lowercase true-- 200string(5) "18:22" 201float(18.377%d) 202int(62558) 203 204--lowercase false-- 205string(5) "18:22" 206float(18.377%d) 207int(62558) 208 209--uppercase TRUE-- 210string(5) "18:22" 211float(18.377%d) 212int(62558) 213 214--uppercase FALSE-- 215string(5) "18:22" 216float(18.377%d) 217int(62558) 218 219--empty string DQ-- 220 221Warning: date_sunset() expects parameter 1 to be long, string given in %s on line %d 222bool(false) 223 224Warning: date_sunset() expects parameter 1 to be long, string given in %s on line %d 225bool(false) 226 227Warning: date_sunset() expects parameter 1 to be long, string given in %s on line %d 228bool(false) 229 230--empty string SQ-- 231 232Warning: date_sunset() expects parameter 1 to be long, string given in %s on line %d 233bool(false) 234 235Warning: date_sunset() expects parameter 1 to be long, string given in %s on line %d 236bool(false) 237 238Warning: date_sunset() expects parameter 1 to be long, string given in %s on line %d 239bool(false) 240 241--string DQ-- 242 243Warning: date_sunset() expects parameter 1 to be long, string given in %s on line %d 244bool(false) 245 246Warning: date_sunset() expects parameter 1 to be long, string given in %s on line %d 247bool(false) 248 249Warning: date_sunset() expects parameter 1 to be long, string given in %s on line %d 250bool(false) 251 252--string SQ-- 253 254Warning: date_sunset() expects parameter 1 to be long, string given in %s on line %d 255bool(false) 256 257Warning: date_sunset() expects parameter 1 to be long, string given in %s on line %d 258bool(false) 259 260Warning: date_sunset() expects parameter 1 to be long, string given in %s on line %d 261bool(false) 262 263--mixed case string-- 264 265Warning: date_sunset() expects parameter 1 to be long, string given in %s on line %d 266bool(false) 267 268Warning: date_sunset() expects parameter 1 to be long, string given in %s on line %d 269bool(false) 270 271Warning: date_sunset() expects parameter 1 to be long, string given in %s on line %d 272bool(false) 273 274--heredoc-- 275 276Warning: date_sunset() expects parameter 1 to be long, string given in %s on line %d 277bool(false) 278 279Warning: date_sunset() expects parameter 1 to be long, string given in %s on line %d 280bool(false) 281 282Warning: date_sunset() expects parameter 1 to be long, string given in %s on line %d 283bool(false) 284 285--instance of classWithToString-- 286 287Warning: date_sunset() expects parameter 1 to be long, object given in %s on line %d 288bool(false) 289 290Warning: date_sunset() expects parameter 1 to be long, object given in %s on line %d 291bool(false) 292 293Warning: date_sunset() expects parameter 1 to be long, object given in %s on line %d 294bool(false) 295 296--instance of classWithoutToString-- 297 298Warning: date_sunset() expects parameter 1 to be long, object given in %s on line %d 299bool(false) 300 301Warning: date_sunset() expects parameter 1 to be long, object given in %s on line %d 302bool(false) 303 304Warning: date_sunset() expects parameter 1 to be long, object given in %s on line %d 305bool(false) 306 307--undefined var-- 308string(5) "18:22" 309float(18.377%d) 310int(62558) 311 312--unset var-- 313string(5) "18:22" 314float(18.377%d) 315int(62558) 316===DONE=== 317