fscanf_variation51.phpt 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. --TEST--
  2. Test fscanf() function: usage variations - file opened in write only mode
  3. --FILE--
  4. <?php
  5. /* Test fscanf() to scan a file for read when file is opened inwrite only mode */
  6. $file_path = __DIR__;
  7. echo "*** Test fscanf(): to read from a file opened in write only mode ***\n";
  8. // create a file
  9. $filename = "$file_path/fscanf_variation51.tmp";
  10. $file_handle = fopen($filename, "w");
  11. if($file_handle == false)
  12. exit("Error:failed to open file $filename");
  13. //writing data to the file
  14. @fwrite($file_handle,"sample text\n");
  15. //closing the file
  16. fclose($file_handle);
  17. // various formats
  18. $formats = array( "%d", "%f", "%e", "%u", " %s", "%x", "%o");
  19. $counter = 1;
  20. // various write only modes
  21. $modes = array("w", "wb", "wt",
  22. "a", "ab", "at",
  23. "x", "xb", "xt"
  24. );
  25. $counter = 1;
  26. // reading the values from file using different integer formats
  27. foreach($modes as $mode) {
  28. $file_handle = fopen($filename, $mode);
  29. if($file_handle == false) {
  30. exit("Error:failed to open file $filename");
  31. }
  32. echo "\n-- iteration $counter --\n";
  33. foreach($formats as $format) {
  34. var_dump( fscanf($file_handle,$format) );
  35. rewind($file_handle);
  36. }
  37. $counter++;
  38. fclose($file_handle);
  39. unlink($filename);
  40. }
  41. echo "\n*** Done ***";
  42. ?>
  43. --CLEAN--
  44. <?php
  45. $file_path = __DIR__;
  46. $filename = "$file_path/fscanf_variation51.tmp";
  47. if(file_exists($filename)) {
  48. unlink($filename);
  49. }
  50. ?>
  51. --EXPECTF--
  52. *** Test fscanf(): to read from a file opened in write only mode ***
  53. -- iteration 1 --
  54. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  55. bool(false)
  56. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  57. bool(false)
  58. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  59. bool(false)
  60. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  61. bool(false)
  62. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  63. bool(false)
  64. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  65. bool(false)
  66. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  67. bool(false)
  68. -- iteration 2 --
  69. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  70. bool(false)
  71. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  72. bool(false)
  73. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  74. bool(false)
  75. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  76. bool(false)
  77. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  78. bool(false)
  79. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  80. bool(false)
  81. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  82. bool(false)
  83. -- iteration 3 --
  84. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  85. bool(false)
  86. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  87. bool(false)
  88. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  89. bool(false)
  90. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  91. bool(false)
  92. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  93. bool(false)
  94. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  95. bool(false)
  96. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  97. bool(false)
  98. -- iteration 4 --
  99. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  100. bool(false)
  101. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  102. bool(false)
  103. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  104. bool(false)
  105. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  106. bool(false)
  107. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  108. bool(false)
  109. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  110. bool(false)
  111. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  112. bool(false)
  113. -- iteration 5 --
  114. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  115. bool(false)
  116. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  117. bool(false)
  118. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  119. bool(false)
  120. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  121. bool(false)
  122. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  123. bool(false)
  124. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  125. bool(false)
  126. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  127. bool(false)
  128. -- iteration 6 --
  129. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  130. bool(false)
  131. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  132. bool(false)
  133. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  134. bool(false)
  135. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  136. bool(false)
  137. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  138. bool(false)
  139. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  140. bool(false)
  141. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  142. bool(false)
  143. -- iteration 7 --
  144. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  145. bool(false)
  146. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  147. bool(false)
  148. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  149. bool(false)
  150. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  151. bool(false)
  152. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  153. bool(false)
  154. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  155. bool(false)
  156. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  157. bool(false)
  158. -- iteration 8 --
  159. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  160. bool(false)
  161. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  162. bool(false)
  163. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  164. bool(false)
  165. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  166. bool(false)
  167. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  168. bool(false)
  169. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  170. bool(false)
  171. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  172. bool(false)
  173. -- iteration 9 --
  174. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  175. bool(false)
  176. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  177. bool(false)
  178. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  179. bool(false)
  180. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  181. bool(false)
  182. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  183. bool(false)
  184. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  185. bool(false)
  186. Notice: fscanf(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  187. bool(false)
  188. *** Done ***