fgetc_variation1.phpt 2.1 KB

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