fgets_variation1.phpt 3.0 KB

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