1--TEST-- 2Test fgetc() function : usage variations - read when file pointer at EOF 3--FILE-- 4<?php 5/* 6 Prototype: string fgetc ( resource $handle ); 7 Description: Gets character from file pointer 8*/ 9// include the header for common test function 10include ("file.inc"); 11 12echo "*** Testing fgetc() : usage variations ***\n"; 13echo "-- Testing fgetc() with file whose file pointer is pointing to EOF --\n"; 14// create a file 15create_files(dirname(__FILE__), 1, "text_with_new_line", 0755, 1, "w", "fgetc_variation"); 16 17$filename = dirname(__FILE__)."/fgetc_variation1.tmp"; 18 19// loop to check the file opened in different read modes 20$file_modes = array("r", "rb", "rt", "r+", "r+b", "r+t"); 21$loop_counter =0; 22for(; $loop_counter < count($file_modes); $loop_counter++) { 23 // print the hearder 24 echo "-- File opened in mode : $file_modes[$loop_counter] --\n"; 25 // open the file 26 $file_handle = fopen ($filename, $file_modes[$loop_counter]); 27 if (!$file_handle) { 28 echo "Error: failed to open file $filename! \n"; 29 exit(); 30 } 31 32 // seek to end of the file and try fgetc() 33 var_dump( fseek($file_handle, 0, SEEK_END) ); // set file pointer to eof 34 var_dump( feof($file_handle) ); // expected false 35 var_dump( ftell($file_handle) ); // ensure that file pointer is at eof 36 var_dump( fgetc($file_handle) ); // try n read a char, none expected 37 var_dump( feof($file_handle) ); // ensure that file pointer is at eof 38 var_dump( ftell($file_handle) ); // file pointer position 39 40 // close the file handle 41 fclose($file_handle); 42} 43echo "Done\n"; 44?> 45--CLEAN-- 46<?php 47unlink( dirname(__FILE__)."/fgetc_variation1.tmp"); 48?> 49--EXPECTF-- 50*** Testing fgetc() : usage variations *** 51-- Testing fgetc() with file whose file pointer is pointing to EOF -- 52-- File opened in mode : r -- 53int(0) 54bool(false) 55int(1024) 56bool(false) 57bool(true) 58int(1024) 59-- File opened in mode : rb -- 60int(0) 61bool(false) 62int(1024) 63bool(false) 64bool(true) 65int(1024) 66-- File opened in mode : rt -- 67int(0) 68bool(false) 69int(1024) 70bool(false) 71bool(true) 72int(1024) 73-- File opened in mode : r+ -- 74int(0) 75bool(false) 76int(1024) 77bool(false) 78bool(true) 79int(1024) 80-- File opened in mode : r+b -- 81int(0) 82bool(false) 83int(1024) 84bool(false) 85bool(true) 86int(1024) 87-- File opened in mode : r+t -- 88int(0) 89bool(false) 90int(1024) 91bool(false) 92bool(true) 93int(1024) 94Done 95