fgetc_variation4.phpt 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. --TEST--
  2. Test fgetc() function : usage variations - different read modes
  3. --FILE--
  4. <?php
  5. /* read from fie using fgetc, file opened using different
  6. read read modes */
  7. echo "*** Testing fgetc() : usage variations ***\n";
  8. echo "-- Testing fgetc() with files opened with different read modes --\n";
  9. $file_modes = array( "a+", "a+b", "a+t",
  10. "x+", "x+b", "x+t",
  11. "w+", "w+b", "w+t" );
  12. $filename = __DIR__."/fgetc_variation4.tmp";
  13. foreach ($file_modes as $file_mode ) {
  14. echo "-- File opened in mode : $file_mode --\n";
  15. $file_handle = fopen($filename, $file_mode);
  16. if(!$file_handle) {
  17. echo "Error: failed to open file $filename!\n";
  18. exit();
  19. }
  20. $data = "fgetc\n test";
  21. fwrite($file_handle, $data);
  22. // rewind the file pointer to beginning of the file
  23. var_dump( rewind($file_handle) );
  24. var_dump( ftell($file_handle) );
  25. var_dump( feof($file_handle) );
  26. // read from file, at least 7 chars
  27. for($counter =0; $counter < 7; $counter ++) {
  28. var_dump( fgetc($file_handle) ); // expected : 1 char
  29. var_dump( ftell($file_handle) );
  30. var_dump( feof($file_handle) ); // check if end of file pointer is set
  31. }
  32. // close the file
  33. fclose($file_handle);
  34. // delete the file
  35. unlink($filename);
  36. }
  37. echo "Done\n";
  38. ?>
  39. --EXPECT--
  40. *** Testing fgetc() : usage variations ***
  41. -- Testing fgetc() with files opened with different read modes --
  42. -- File opened in mode : a+ --
  43. bool(true)
  44. int(0)
  45. bool(false)
  46. string(1) "f"
  47. int(1)
  48. bool(false)
  49. string(1) "g"
  50. int(2)
  51. bool(false)
  52. string(1) "e"
  53. int(3)
  54. bool(false)
  55. string(1) "t"
  56. int(4)
  57. bool(false)
  58. string(1) "c"
  59. int(5)
  60. bool(false)
  61. string(1) "
  62. "
  63. int(6)
  64. bool(false)
  65. string(1) " "
  66. int(7)
  67. bool(false)
  68. -- File opened in mode : a+b --
  69. bool(true)
  70. int(0)
  71. bool(false)
  72. string(1) "f"
  73. int(1)
  74. bool(false)
  75. string(1) "g"
  76. int(2)
  77. bool(false)
  78. string(1) "e"
  79. int(3)
  80. bool(false)
  81. string(1) "t"
  82. int(4)
  83. bool(false)
  84. string(1) "c"
  85. int(5)
  86. bool(false)
  87. string(1) "
  88. "
  89. int(6)
  90. bool(false)
  91. string(1) " "
  92. int(7)
  93. bool(false)
  94. -- File opened in mode : a+t --
  95. bool(true)
  96. int(0)
  97. bool(false)
  98. string(1) "f"
  99. int(1)
  100. bool(false)
  101. string(1) "g"
  102. int(2)
  103. bool(false)
  104. string(1) "e"
  105. int(3)
  106. bool(false)
  107. string(1) "t"
  108. int(4)
  109. bool(false)
  110. string(1) "c"
  111. int(5)
  112. bool(false)
  113. string(1) "
  114. "
  115. int(6)
  116. bool(false)
  117. string(1) " "
  118. int(7)
  119. bool(false)
  120. -- File opened in mode : x+ --
  121. bool(true)
  122. int(0)
  123. bool(false)
  124. string(1) "f"
  125. int(1)
  126. bool(false)
  127. string(1) "g"
  128. int(2)
  129. bool(false)
  130. string(1) "e"
  131. int(3)
  132. bool(false)
  133. string(1) "t"
  134. int(4)
  135. bool(false)
  136. string(1) "c"
  137. int(5)
  138. bool(false)
  139. string(1) "
  140. "
  141. int(6)
  142. bool(false)
  143. string(1) " "
  144. int(7)
  145. bool(false)
  146. -- File opened in mode : x+b --
  147. bool(true)
  148. int(0)
  149. bool(false)
  150. string(1) "f"
  151. int(1)
  152. bool(false)
  153. string(1) "g"
  154. int(2)
  155. bool(false)
  156. string(1) "e"
  157. int(3)
  158. bool(false)
  159. string(1) "t"
  160. int(4)
  161. bool(false)
  162. string(1) "c"
  163. int(5)
  164. bool(false)
  165. string(1) "
  166. "
  167. int(6)
  168. bool(false)
  169. string(1) " "
  170. int(7)
  171. bool(false)
  172. -- File opened in mode : x+t --
  173. bool(true)
  174. int(0)
  175. bool(false)
  176. string(1) "f"
  177. int(1)
  178. bool(false)
  179. string(1) "g"
  180. int(2)
  181. bool(false)
  182. string(1) "e"
  183. int(3)
  184. bool(false)
  185. string(1) "t"
  186. int(4)
  187. bool(false)
  188. string(1) "c"
  189. int(5)
  190. bool(false)
  191. string(1) "
  192. "
  193. int(6)
  194. bool(false)
  195. string(1) " "
  196. int(7)
  197. bool(false)
  198. -- File opened in mode : w+ --
  199. bool(true)
  200. int(0)
  201. bool(false)
  202. string(1) "f"
  203. int(1)
  204. bool(false)
  205. string(1) "g"
  206. int(2)
  207. bool(false)
  208. string(1) "e"
  209. int(3)
  210. bool(false)
  211. string(1) "t"
  212. int(4)
  213. bool(false)
  214. string(1) "c"
  215. int(5)
  216. bool(false)
  217. string(1) "
  218. "
  219. int(6)
  220. bool(false)
  221. string(1) " "
  222. int(7)
  223. bool(false)
  224. -- File opened in mode : w+b --
  225. bool(true)
  226. int(0)
  227. bool(false)
  228. string(1) "f"
  229. int(1)
  230. bool(false)
  231. string(1) "g"
  232. int(2)
  233. bool(false)
  234. string(1) "e"
  235. int(3)
  236. bool(false)
  237. string(1) "t"
  238. int(4)
  239. bool(false)
  240. string(1) "c"
  241. int(5)
  242. bool(false)
  243. string(1) "
  244. "
  245. int(6)
  246. bool(false)
  247. string(1) " "
  248. int(7)
  249. bool(false)
  250. -- File opened in mode : w+t --
  251. bool(true)
  252. int(0)
  253. bool(false)
  254. string(1) "f"
  255. int(1)
  256. bool(false)
  257. string(1) "g"
  258. int(2)
  259. bool(false)
  260. string(1) "e"
  261. int(3)
  262. bool(false)
  263. string(1) "t"
  264. int(4)
  265. bool(false)
  266. string(1) "c"
  267. int(5)
  268. bool(false)
  269. string(1) "
  270. "
  271. int(6)
  272. bool(false)
  273. string(1) " "
  274. int(7)
  275. bool(false)
  276. Done