1--TEST-- 2Test fgetc() function : usage variations - different read modes 3--FILE-- 4<?php 5/* 6 Prototype: string fgetc ( resource $handle ); 7 Description: Gets character from file pointer 8*/ 9 10/* read from fie using fgetc, file opened using different 11 read read modes */ 12 13echo "*** Testing fgetc() : usage variations ***\n"; 14echo "-- Testing fgetc() with files opened with different read modes --\n"; 15 16$file_modes = array( "a+", "a+b", "a+t", 17 "x+", "x+b", "x+t", 18 "w+", "w+b", "w+t" ); 19 20$filename = dirname(__FILE__)."/fgetc_variation4.tmp"; 21foreach ($file_modes as $file_mode ) { 22 echo "-- File opened in mode : $file_mode --\n"; 23 24 $file_handle = fopen($filename, $file_mode); 25 if(!$file_handle) { 26 echo "Error: failed to open file $filename!\n"; 27 exit(); 28 } 29 $data = "fgetc\n test"; 30 fwrite($file_handle, $data); 31 32 // rewind the file pointer to begining of the file 33 var_dump( rewind($file_handle) ); 34 var_dump( ftell($file_handle) ); 35 var_dump( feof($file_handle) ); 36 37 // read from file, at least 7 chars 38 for($counter =0; $counter < 7; $counter ++) { 39 var_dump( fgetc($file_handle) ); // expected : 1 char 40 var_dump( ftell($file_handle) ); 41 var_dump( feof($file_handle) ); // check if end of file pointer is set 42 } 43 44 // close the file 45 fclose($file_handle); 46 47 // delete the file 48 unlink($filename); 49} 50 51echo "Done\n"; 52?> 53--EXPECTF-- 54 *** Testing fgetc() : usage variations *** 55-- Testing fgetc() with files opened with different read modes -- 56-- File opened in mode : a+ -- 57bool(true) 58int(0) 59bool(false) 60string(1) "f" 61int(1) 62bool(false) 63string(1) "g" 64int(2) 65bool(false) 66string(1) "e" 67int(3) 68bool(false) 69string(1) "t" 70int(4) 71bool(false) 72string(1) "c" 73int(5) 74bool(false) 75string(1) " 76" 77int(6) 78bool(false) 79string(1) " " 80int(7) 81bool(false) 82-- File opened in mode : a+b -- 83bool(true) 84int(0) 85bool(false) 86string(1) "f" 87int(1) 88bool(false) 89string(1) "g" 90int(2) 91bool(false) 92string(1) "e" 93int(3) 94bool(false) 95string(1) "t" 96int(4) 97bool(false) 98string(1) "c" 99int(5) 100bool(false) 101string(1) " 102" 103int(6) 104bool(false) 105string(1) " " 106int(7) 107bool(false) 108-- File opened in mode : a+t -- 109bool(true) 110int(0) 111bool(false) 112string(1) "f" 113int(1) 114bool(false) 115string(1) "g" 116int(2) 117bool(false) 118string(1) "e" 119int(3) 120bool(false) 121string(1) "t" 122int(4) 123bool(false) 124string(1) "c" 125int(5) 126bool(false) 127string(1) " 128" 129int(6) 130bool(false) 131string(1) " " 132int(7) 133bool(false) 134-- File opened in mode : x+ -- 135bool(true) 136int(0) 137bool(false) 138string(1) "f" 139int(1) 140bool(false) 141string(1) "g" 142int(2) 143bool(false) 144string(1) "e" 145int(3) 146bool(false) 147string(1) "t" 148int(4) 149bool(false) 150string(1) "c" 151int(5) 152bool(false) 153string(1) " 154" 155int(6) 156bool(false) 157string(1) " " 158int(7) 159bool(false) 160-- File opened in mode : x+b -- 161bool(true) 162int(0) 163bool(false) 164string(1) "f" 165int(1) 166bool(false) 167string(1) "g" 168int(2) 169bool(false) 170string(1) "e" 171int(3) 172bool(false) 173string(1) "t" 174int(4) 175bool(false) 176string(1) "c" 177int(5) 178bool(false) 179string(1) " 180" 181int(6) 182bool(false) 183string(1) " " 184int(7) 185bool(false) 186-- File opened in mode : x+t -- 187bool(true) 188int(0) 189bool(false) 190string(1) "f" 191int(1) 192bool(false) 193string(1) "g" 194int(2) 195bool(false) 196string(1) "e" 197int(3) 198bool(false) 199string(1) "t" 200int(4) 201bool(false) 202string(1) "c" 203int(5) 204bool(false) 205string(1) " 206" 207int(6) 208bool(false) 209string(1) " " 210int(7) 211bool(false) 212-- File opened in mode : w+ -- 213bool(true) 214int(0) 215bool(false) 216string(1) "f" 217int(1) 218bool(false) 219string(1) "g" 220int(2) 221bool(false) 222string(1) "e" 223int(3) 224bool(false) 225string(1) "t" 226int(4) 227bool(false) 228string(1) "c" 229int(5) 230bool(false) 231string(1) " 232" 233int(6) 234bool(false) 235string(1) " " 236int(7) 237bool(false) 238-- File opened in mode : w+b -- 239bool(true) 240int(0) 241bool(false) 242string(1) "f" 243int(1) 244bool(false) 245string(1) "g" 246int(2) 247bool(false) 248string(1) "e" 249int(3) 250bool(false) 251string(1) "t" 252int(4) 253bool(false) 254string(1) "c" 255int(5) 256bool(false) 257string(1) " 258" 259int(6) 260bool(false) 261string(1) " " 262int(7) 263bool(false) 264-- File opened in mode : w+t -- 265bool(true) 266int(0) 267bool(false) 268string(1) "f" 269int(1) 270bool(false) 271string(1) "g" 272int(2) 273bool(false) 274string(1) "e" 275int(3) 276bool(false) 277string(1) "t" 278int(4) 279bool(false) 280string(1) "c" 281int(5) 282bool(false) 283string(1) " 284" 285int(6) 286bool(false) 287string(1) " " 288int(7) 289bool(false) 290Done