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