fgetc_variation3.phpt 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. --TEST--
  2. Test fgetc() function : usage variations - write only modes (Bug #42036)
  3. --FILE--
  4. <?php
  5. /*
  6. Description: Gets character from file pointer
  7. */
  8. /* try fgetc on files which are opened in non readable modes
  9. w, wb, wt,
  10. a, ab, at,
  11. x, xb, xt
  12. */
  13. // include the header for common test function
  14. include ("file.inc");
  15. echo "*** Testing fgetc() with file opened in write only mode ***\n";
  16. $file_modes = array("w", "wb", "wt", "a", "ab", "at", "x", "xb", "xt");
  17. $filename = __DIR__."/fgetc_variation3.tmp";
  18. foreach ($file_modes as $file_mode ) {
  19. echo "-- File opened in mode : $file_mode --\n";
  20. $file_handle = fopen($filename, $file_mode);
  21. if(!$file_handle) {
  22. echo "Error: failed to open file $filename!\n";
  23. exit();
  24. }
  25. $data = "fgetc_variation test";
  26. fwrite($file_handle, $data);
  27. // rewind the file pointer to beginning of the file
  28. var_dump( rewind($file_handle) );
  29. var_dump( ftell($file_handle) );
  30. var_dump( feof($file_handle) );
  31. // read from file
  32. var_dump( fgetc($file_handle) ); // expected : no chars should be read
  33. var_dump( ftell($file_handle) ); // ensure that file pointer position is not changed
  34. var_dump( feof($file_handle) ); // check if end of file pointer is set
  35. // close the file
  36. fclose($file_handle);
  37. // delete the file
  38. unlink($filename);
  39. }
  40. echo "Done\n";
  41. ?>
  42. --EXPECTF--
  43. *** Testing fgetc() with file opened in write only mode ***
  44. -- File opened in mode : w --
  45. bool(true)
  46. int(0)
  47. bool(false)
  48. Notice: fgetc(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  49. bool(false)
  50. int(0)
  51. bool(false)
  52. -- File opened in mode : wb --
  53. bool(true)
  54. int(0)
  55. bool(false)
  56. Notice: fgetc(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  57. bool(false)
  58. int(0)
  59. bool(false)
  60. -- File opened in mode : wt --
  61. bool(true)
  62. int(0)
  63. bool(false)
  64. Notice: fgetc(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  65. bool(false)
  66. int(0)
  67. bool(false)
  68. -- File opened in mode : a --
  69. bool(true)
  70. int(0)
  71. bool(false)
  72. Notice: fgetc(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  73. bool(false)
  74. int(0)
  75. bool(false)
  76. -- File opened in mode : ab --
  77. bool(true)
  78. int(0)
  79. bool(false)
  80. Notice: fgetc(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  81. bool(false)
  82. int(0)
  83. bool(false)
  84. -- File opened in mode : at --
  85. bool(true)
  86. int(0)
  87. bool(false)
  88. Notice: fgetc(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  89. bool(false)
  90. int(0)
  91. bool(false)
  92. -- File opened in mode : x --
  93. bool(true)
  94. int(0)
  95. bool(false)
  96. Notice: fgetc(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  97. bool(false)
  98. int(0)
  99. bool(false)
  100. -- File opened in mode : xb --
  101. bool(true)
  102. int(0)
  103. bool(false)
  104. Notice: fgetc(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  105. bool(false)
  106. int(0)
  107. bool(false)
  108. -- File opened in mode : xt --
  109. bool(true)
  110. int(0)
  111. bool(false)
  112. Notice: fgetc(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  113. bool(false)
  114. int(0)
  115. bool(false)
  116. Done