1--TEST-- 2Test DateTime::format() function : usage variation - Passing unexpected values to first argument $format. 3--FILE-- 4<?php 5/* Prototype : public string DateTime::format ( string $format ) 6 * Description: Returns date formatted according to given format 7 * Source code: ext/date/php_date.c 8 * Alias to functions: date_format 9 */ 10 11echo "*** Testing DateTime::format() : usage variation - unexpected values to first argument \$format***\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$object = new DateTime("2005-07-14 22:30:41"); 99 100foreach($inputs as $variation =>$format) { 101 echo "\n-- $variation --\n"; 102 var_dump( $object->format($format) ); 103}; 104 105// closing the resource 106fclose( $file_handle ); 107 108?> 109===DONE=== 110--EXPECTF-- 111*** Testing DateTime::format() : usage variation - unexpected values to first argument $format*** 112 113-- int 0 -- 114string(1) "0" 115 116-- int 1 -- 117string(1) "1" 118 119-- int 12345 -- 120string(5) "12345" 121 122-- int -12345 -- 123string(6) "-12345" 124 125-- float 10.5 -- 126string(4) "10.5" 127 128-- float -10.5 -- 129string(5) "-10.5" 130 131-- float .5 -- 132string(3) "0.5" 133 134-- empty array -- 135 136Warning: DateTime::format() expects parameter 1 to be string, array given in %s on line %d 137bool(false) 138 139-- int indexed array -- 140 141Warning: DateTime::format() expects parameter 1 to be string, array given in %s on line %d 142bool(false) 143 144-- associative array -- 145 146Warning: DateTime::format() expects parameter 1 to be string, array given in %s on line %d 147bool(false) 148 149-- nested arrays -- 150 151Warning: DateTime::format() expects parameter 1 to be string, array given in %s on line %d 152bool(false) 153 154-- uppercase NULL -- 155string(0) "" 156 157-- lowercase null -- 158string(0) "" 159 160-- lowercase true -- 161string(1) "1" 162 163-- lowercase false -- 164string(0) "" 165 166-- uppercase TRUE -- 167string(1) "1" 168 169-- uppercase FALSE -- 170string(0) "" 171 172-- empty string DQ -- 173string(0) "" 174 175-- empty string SQ -- 176string(0) "" 177 178-- string DQ -- 179string(40) "4131Thu, 14 Jul 2005 22:30:41 +010030710" 180 181-- string SQ -- 182string(40) "4131Thu, 14 Jul 2005 22:30:41 +010030710" 183 184-- mixed case string -- 185string(40) "41BSTThu, 14 Jul 2005 22:30:41 +01001722" 186 187-- heredoc -- 188string(82) "10Europe/LondonThursdayThursday2005 42005Thu, 14 Jul 2005 22:30:41 +0100Thursday14" 189 190-- instance of classWithToString -- 191string(66) "CThursdaypm4141 PM 2005b14Europe/London2005-07-14T22:30:41+01:0031" 192 193-- instance of classWithoutToString -- 194 195Warning: DateTime::format() expects parameter 1 to be string, object given in %s on line %d 196bool(false) 197 198-- undefined var -- 199string(0) "" 200 201-- unset var -- 202string(0) "" 203 204-- resource -- 205 206Warning: DateTime::format() expects parameter 1 to be string, resource given in %s on line %d 207bool(false) 208===DONE=== 209