1--TEST-- 2Test fscanf() function: usage variations - file opened in write only mode 3--FILE-- 4<?php 5 6/* Test fscanf() to scan a file for read when file is opened inwrite only mode */ 7 8$file_path = __DIR__; 9 10echo "*** Test fscanf(): to read from a file opened in write only mode ***\n"; 11 12// create a file 13$filename = "$file_path/fscanf_variation51.tmp"; 14$file_handle = fopen($filename, "w"); 15if($file_handle == false) 16 exit("Error:failed to open file $filename"); 17//writing data to the file 18@fwrite($file_handle,"sample text\n"); 19 20//closing the file 21fclose($file_handle); 22 23// various formats 24$formats = array( "%d", "%f", "%e", "%u", " %s", "%x", "%o"); 25 26$counter = 1; 27 28// various write only modes 29$modes = array("w", "wb", "wt", 30 "a", "ab", "at", 31 "x", "xb", "xt" 32 ); 33 34$counter = 1; 35// reading the values from file using different integer formats 36foreach($modes as $mode) { 37 38 $file_handle = fopen($filename, $mode); 39 if($file_handle == false) { 40 exit("Error:failed to open file $filename"); 41 } 42 echo "\n-- iteration $counter --\n"; 43 44 foreach($formats as $format) { 45 var_dump( fscanf($file_handle,$format) ); 46 rewind($file_handle); 47 } 48 $counter++; 49 fclose($file_handle); 50 unlink($filename); 51} 52 53echo "\n*** Done ***"; 54?> 55--CLEAN-- 56<?php 57$file_path = __DIR__; 58$filename = "$file_path/fscanf_variation51.tmp"; 59if(file_exists($filename)) { 60 unlink($filename); 61} 62?> 63--EXPECTF-- 64*** Test fscanf(): to read from a file opened in write only mode *** 65 66-- iteration 1 -- 67 68Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 69bool(false) 70 71Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 72bool(false) 73 74Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 75bool(false) 76 77Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 78bool(false) 79 80Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 81bool(false) 82 83Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 84bool(false) 85 86Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 87bool(false) 88 89-- iteration 2 -- 90 91Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 92bool(false) 93 94Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 95bool(false) 96 97Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 98bool(false) 99 100Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 101bool(false) 102 103Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 104bool(false) 105 106Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 107bool(false) 108 109Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 110bool(false) 111 112-- iteration 3 -- 113 114Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 115bool(false) 116 117Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 118bool(false) 119 120Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 121bool(false) 122 123Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 124bool(false) 125 126Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 127bool(false) 128 129Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 130bool(false) 131 132Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 133bool(false) 134 135-- iteration 4 -- 136 137Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 138bool(false) 139 140Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 141bool(false) 142 143Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 144bool(false) 145 146Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 147bool(false) 148 149Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 150bool(false) 151 152Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 153bool(false) 154 155Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 156bool(false) 157 158-- iteration 5 -- 159 160Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 161bool(false) 162 163Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 164bool(false) 165 166Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 167bool(false) 168 169Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 170bool(false) 171 172Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 173bool(false) 174 175Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 176bool(false) 177 178Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 179bool(false) 180 181-- iteration 6 -- 182 183Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 184bool(false) 185 186Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 187bool(false) 188 189Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 190bool(false) 191 192Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 193bool(false) 194 195Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 196bool(false) 197 198Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 199bool(false) 200 201Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 202bool(false) 203 204-- iteration 7 -- 205 206Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 207bool(false) 208 209Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 210bool(false) 211 212Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 213bool(false) 214 215Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 216bool(false) 217 218Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 219bool(false) 220 221Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 222bool(false) 223 224Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 225bool(false) 226 227-- iteration 8 -- 228 229Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 230bool(false) 231 232Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 233bool(false) 234 235Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 236bool(false) 237 238Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 239bool(false) 240 241Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 242bool(false) 243 244Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 245bool(false) 246 247Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 248bool(false) 249 250-- iteration 9 -- 251 252Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 253bool(false) 254 255Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 256bool(false) 257 258Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 259bool(false) 260 261Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 262bool(false) 263 264Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 265bool(false) 266 267Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 268bool(false) 269 270Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 271bool(false) 272 273*** Done *** 274