1--TEST-- 2Test new DateTime() function : usage variation - Passing unexpected values to second argument $timezone. 3--FILE-- 4<?php 5/* Prototype : DateTime::__construct ([ string $time="now" [, DateTimeZone $timezone=NULL ]] ) 6 * Description: Returns new DateTime object 7 * Source code: ext/date/php_date.c 8 * Alias to functions: date_create 9 */ 10 11echo "*** Testing new DateTime() : usage variation - unexpected values to second argument \$timezone***\n"; 12 13//Set the default time zone 14date_default_timezone_set("Europe/London"); 15 16//get an unset variable 17$unset_var = 10; 18unset ($unset_var); 19 20// define some classes 21class classWithToString 22{ 23 public function __toString() { 24 return "Class A object"; 25 } 26} 27 28class classWithoutToString 29{ 30} 31 32// heredoc string 33$heredoc = <<<EOT 34hello world 35EOT; 36 37// add arrays 38$index_array = array (1, 2, 3); 39$assoc_array = array ('one' => 1, 'two' => 2); 40 41// resource 42$file_handle = fopen(__FILE__, 'r'); 43 44//array of values to iterate over 45$inputs = array( 46 47 // int data 48 'int 0' => 0, 49 'int 1' => 1, 50 'int 12345' => 12345, 51 'int -12345' => -12345, 52 53 // float data 54 'float 10.5' => 10.5, 55 'float -10.5' => -10.5, 56 'float .5' => .5, 57 58 // array data 59 'empty array' => array(), 60 'int indexed array' => $index_array, 61 'associative array' => $assoc_array, 62 'nested arrays' => array('foo', $index_array, $assoc_array), 63 64 // null data 65 'uppercase NULL' => NULL, 66 'lowercase null' => null, 67 68 // boolean data 69 'lowercase true' => true, 70 'lowercase false' =>false, 71 'uppercase TRUE' =>TRUE, 72 'uppercase FALSE' =>FALSE, 73 74 // empty data 75 'empty string DQ' => "", 76 'empty string SQ' => '', 77 78 // string data 79 'string DQ' => "string", 80 'string SQ' => 'string', 81 'mixed case string' => "sTrInG", 82 'heredoc' => $heredoc, 83 84 // object data 85 'instance of classWithToString' => new classWithToString(), 86 'instance of classWithoutToString' => new classWithoutToString(), 87 88 // undefined data 89 'undefined var' => @$undefined_var, 90 91 // unset data 92 'unset var' => @$unset_var, 93 94 // resource 95 'resource' => $file_handle 96); 97 98$time = "2005-07-14 22:30:41"; 99 100foreach($inputs as $variation =>$timezone) { 101 echo "\n-- $variation --\n"; 102 103 try { 104 var_dump( new DateTime($time, $timezone) ); 105 } catch(Exception $e) { 106 $msg = $e->getMessage(); 107 echo "FAILED: " . $msg . "\n"; 108 } 109 110}; 111 112// closing the resource 113fclose( $file_handle); 114 115?> 116===DONE=== 117--EXPECTF-- 118*** Testing new DateTime() : usage variation - unexpected values to second argument $timezone*** 119 120-- int 0 -- 121FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, integer given 122 123-- int 1 -- 124FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, integer given 125 126-- int 12345 -- 127FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, integer given 128 129-- int -12345 -- 130FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, integer given 131 132-- float 10.5 -- 133FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, double given 134 135-- float -10.5 -- 136FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, double given 137 138-- float .5 -- 139FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, double given 140 141-- empty array -- 142FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, array given 143 144-- int indexed array -- 145FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, array given 146 147-- associative array -- 148FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, array given 149 150-- nested arrays -- 151FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, array given 152 153-- uppercase NULL -- 154object(DateTime)#%d (3) { 155 ["date"]=> 156 string(19) "2005-07-14 22:30:41" 157 ["timezone_type"]=> 158 int(3) 159 ["timezone"]=> 160 string(13) "Europe/London" 161} 162 163-- lowercase null -- 164object(DateTime)#%d (3) { 165 ["date"]=> 166 string(19) "2005-07-14 22:30:41" 167 ["timezone_type"]=> 168 int(3) 169 ["timezone"]=> 170 string(13) "Europe/London" 171} 172 173-- lowercase true -- 174FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, boolean given 175 176-- lowercase false -- 177FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, boolean given 178 179-- uppercase TRUE -- 180FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, boolean given 181 182-- uppercase FALSE -- 183FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, boolean given 184 185-- empty string DQ -- 186FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, string given 187 188-- empty string SQ -- 189FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, string given 190 191-- string DQ -- 192FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, string given 193 194-- string SQ -- 195FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, string given 196 197-- mixed case string -- 198FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, string given 199 200-- heredoc -- 201FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, string given 202 203-- instance of classWithToString -- 204FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, object given 205 206-- instance of classWithoutToString -- 207FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, object given 208 209-- undefined var -- 210object(DateTime)#%d (3) { 211 ["date"]=> 212 string(19) "2005-07-14 22:30:41" 213 ["timezone_type"]=> 214 int(3) 215 ["timezone"]=> 216 string(13) "Europe/London" 217} 218 219-- unset var -- 220object(DateTime)#%d (3) { 221 ["date"]=> 222 string(19) "2005-07-14 22:30:41" 223 ["timezone_type"]=> 224 int(3) 225 ["timezone"]=> 226 string(13) "Europe/London" 227} 228 229-- resource -- 230FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, resource given 231===DONE=== 232 233