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