1--TEST-- 2Test gmdate() function : usage variation - Passing unexpected values to format argument . 3--FILE-- 4<?php 5/* Prototype : string gmdate(string format [, long timestamp]) 6 * Description: Format a GMT date/time 7 * Source code: ext/date/php_date.c 8 * Alias to functions: 9 */ 10 11echo "*** Testing gmdate() : usage variation ***\n"; 12 13// Initialise all required variables 14date_default_timezone_set('UTC'); 15$timestamp = mktime(8, 8, 8, 8, 8, 2008); 16 17//get an unset variable 18$unset_var = 10; 19unset ($unset_var); 20 21// define some classes 22class classWithToString 23{ 24 public function __toString() { 25 return "Class A object"; 26 } 27} 28 29class classWithoutToString 30{ 31} 32 33// heredoc string 34$heredoc = <<<EOT 35hello world 36EOT; 37 38// add arrays 39$index_array = array (1, 2, 3); 40$assoc_array = array ('one' => 1, 'two' => 2); 41 42//array of values to iterate over 43$inputs = array( 44 45 // int data 46 'int 0' => 0, 47 'int 1' => 1, 48 'int 12345' => 12345, 49 'int -12345' => -12345, 50 51 // float data 52 'float 10.5' => 10.5, 53 'float -10.5' => -10.5, 54 'float 12.3456789000e10' => 12.3456789000e10, 55 'float -12.3456789000e10' => -12.3456789000e10, 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 // object data 79 'instance of classWithToString' => new classWithToString(), 80 'instance of classWithoutToString' => new classWithoutToString(), 81 82 // undefined data 83 'undefined var' => @$undefined_var, 84 85 // unset data 86 'unset var' => @$unset_var, 87); 88 89// loop through each element of the array for format 90 91foreach($inputs as $key =>$value) { 92 echo "\n--$key--\n"; 93 var_dump( gmdate($value, $timestamp) ); 94 var_dump( gmdate($value) ); 95}; 96 97?> 98===DONE=== 99--EXPECTF-- 100*** Testing gmdate() : usage variation *** 101 102--int 0-- 103string(1) "0" 104string(1) "0" 105 106--int 1-- 107string(1) "1" 108string(1) "1" 109 110--int 12345-- 111string(5) "12345" 112string(5) "12345" 113 114--int -12345-- 115string(6) "-12345" 116string(6) "-12345" 117 118--float 10.5-- 119string(4) "10.5" 120string(4) "10.5" 121 122--float -10.5-- 123string(5) "-10.5" 124string(5) "-10.5" 125 126--float 12.3456789000e10-- 127string(12) "123456789000" 128string(12) "123456789000" 129 130--float -12.3456789000e10-- 131string(13) "-123456789000" 132string(13) "-123456789000" 133 134--float .5-- 135string(3) "0.5" 136string(3) "0.5" 137 138--empty array-- 139 140Warning: gmdate() expects parameter 1 to be string, array given in %s on line %d 141bool(false) 142 143Warning: gmdate() expects parameter 1 to be string, array given in %s on line %d 144bool(false) 145 146--int indexed array-- 147 148Warning: gmdate() expects parameter 1 to be string, array given in %s on line %d 149bool(false) 150 151Warning: gmdate() expects parameter 1 to be string, array given in %s on line %d 152bool(false) 153 154--associative array-- 155 156Warning: gmdate() expects parameter 1 to be string, array given in %s on line %d 157bool(false) 158 159Warning: gmdate() expects parameter 1 to be string, array given in %s on line %d 160bool(false) 161 162--nested arrays-- 163 164Warning: gmdate() expects parameter 1 to be string, array given in %s on line %d 165bool(false) 166 167Warning: gmdate() expects parameter 1 to be string, array given in %s on line %d 168bool(false) 169 170--uppercase NULL-- 171string(0) "" 172string(0) "" 173 174--lowercase null-- 175string(0) "" 176string(0) "" 177 178--lowercase true-- 179string(1) "1" 180string(1) "1" 181 182--lowercase false-- 183string(0) "" 184string(0) "" 185 186--uppercase TRUE-- 187string(1) "1" 188string(1) "1" 189 190--uppercase FALSE-- 191string(0) "" 192string(0) "" 193 194--empty string DQ-- 195string(0) "" 196string(0) "" 197 198--empty string SQ-- 199string(0) "" 200string(0) "" 201 202--instance of classWithToString-- 203string(53) "CFridayam0808 AM 2008b8UTC2008-08-08T08:08:08+00:0031" 204string(%d) "%s" 205 206--instance of classWithoutToString-- 207 208Warning: gmdate() expects parameter 1 to be string, object given in %s on line %d 209bool(false) 210 211Warning: gmdate() expects parameter 1 to be string, object given in %s on line %d 212bool(false) 213 214--undefined var-- 215string(0) "" 216string(0) "" 217 218--unset var-- 219string(0) "" 220string(0) "" 221===DONE=== 222