fgets_variation6.phpt 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. --TEST--
  2. Test fgets() function : usage variations - read when file pointer at EOF
  3. --SKIPIF--
  4. <?php
  5. if (substr(PHP_OS, 0, 3) == 'WIN') {
  6. die('skip Not valid for Windows');
  7. }
  8. ?>
  9. --FILE--
  10. <?php
  11. // include the file.inc for common test functions
  12. include ("file.inc");
  13. $file_modes = array("w+", "w+b", "w+t",
  14. "a+", "a+b", "a+t",
  15. "x+", "x+b", "x+t");
  16. $file_content_types = array("numeric", "text", "text_with_new_line", "alphanumeric");
  17. echo "*** Testing fgets() : usage variations ***\n";
  18. $filename = __DIR__."/fgets_variation6.tmp";
  19. foreach($file_modes as $file_mode) {
  20. echo "\n-- Testing fgets() with file opened using mode $file_mode --\n";
  21. foreach($file_content_types as $file_content_type) {
  22. echo "-- File content type : $file_content_type --\n";
  23. /* create files with $file_content_type */
  24. $file_handle = fopen($filename, $file_mode);
  25. $data = fill_file($file_handle, $file_content_type, 50);
  26. if ( !$file_handle ) {
  27. echo "Error: failed to open file $filename!";
  28. exit();
  29. }
  30. echo "-- fgets() with file pointer pointing at EOF --\n";
  31. // seek to end of the file and try fgets()
  32. var_dump( fseek($file_handle, 0, SEEK_END) ); // set file pointer to eof
  33. var_dump( ftell($file_handle) ); // ensure that file pointer is at eof
  34. var_dump( feof($file_handle) ); // expected false
  35. var_dump( fgets($file_handle) ); // try n read a line, none expected
  36. var_dump( ftell($file_handle) ); // file pointer position
  37. var_dump( feof($file_handle) ); // ensure that file pointer is at eof
  38. //close file
  39. fclose($file_handle);
  40. // delete file
  41. delete_file($filename);
  42. } // file_content_type loop
  43. } // file_mode loop
  44. echo "Done\n";
  45. ?>
  46. --EXPECT--
  47. *** Testing fgets() : usage variations ***
  48. -- Testing fgets() with file opened using mode w+ --
  49. -- File content type : numeric --
  50. -- fgets() with file pointer pointing at EOF --
  51. int(0)
  52. int(50)
  53. bool(false)
  54. bool(false)
  55. int(50)
  56. bool(true)
  57. -- File content type : text --
  58. -- fgets() with file pointer pointing at EOF --
  59. int(0)
  60. int(50)
  61. bool(false)
  62. bool(false)
  63. int(50)
  64. bool(true)
  65. -- File content type : text_with_new_line --
  66. -- fgets() with file pointer pointing at EOF --
  67. int(0)
  68. int(50)
  69. bool(false)
  70. bool(false)
  71. int(50)
  72. bool(true)
  73. -- File content type : alphanumeric --
  74. -- fgets() with file pointer pointing at EOF --
  75. int(0)
  76. int(50)
  77. bool(false)
  78. bool(false)
  79. int(50)
  80. bool(true)
  81. -- Testing fgets() with file opened using mode w+b --
  82. -- File content type : numeric --
  83. -- fgets() with file pointer pointing at EOF --
  84. int(0)
  85. int(50)
  86. bool(false)
  87. bool(false)
  88. int(50)
  89. bool(true)
  90. -- File content type : text --
  91. -- fgets() with file pointer pointing at EOF --
  92. int(0)
  93. int(50)
  94. bool(false)
  95. bool(false)
  96. int(50)
  97. bool(true)
  98. -- File content type : text_with_new_line --
  99. -- fgets() with file pointer pointing at EOF --
  100. int(0)
  101. int(50)
  102. bool(false)
  103. bool(false)
  104. int(50)
  105. bool(true)
  106. -- File content type : alphanumeric --
  107. -- fgets() with file pointer pointing at EOF --
  108. int(0)
  109. int(50)
  110. bool(false)
  111. bool(false)
  112. int(50)
  113. bool(true)
  114. -- Testing fgets() with file opened using mode w+t --
  115. -- File content type : numeric --
  116. -- fgets() with file pointer pointing at EOF --
  117. int(0)
  118. int(50)
  119. bool(false)
  120. bool(false)
  121. int(50)
  122. bool(true)
  123. -- File content type : text --
  124. -- fgets() with file pointer pointing at EOF --
  125. int(0)
  126. int(50)
  127. bool(false)
  128. bool(false)
  129. int(50)
  130. bool(true)
  131. -- File content type : text_with_new_line --
  132. -- fgets() with file pointer pointing at EOF --
  133. int(0)
  134. int(50)
  135. bool(false)
  136. bool(false)
  137. int(50)
  138. bool(true)
  139. -- File content type : alphanumeric --
  140. -- fgets() with file pointer pointing at EOF --
  141. int(0)
  142. int(50)
  143. bool(false)
  144. bool(false)
  145. int(50)
  146. bool(true)
  147. -- Testing fgets() with file opened using mode a+ --
  148. -- File content type : numeric --
  149. -- fgets() with file pointer pointing at EOF --
  150. int(0)
  151. int(50)
  152. bool(false)
  153. bool(false)
  154. int(50)
  155. bool(true)
  156. -- File content type : text --
  157. -- fgets() with file pointer pointing at EOF --
  158. int(0)
  159. int(50)
  160. bool(false)
  161. bool(false)
  162. int(50)
  163. bool(true)
  164. -- File content type : text_with_new_line --
  165. -- fgets() with file pointer pointing at EOF --
  166. int(0)
  167. int(50)
  168. bool(false)
  169. bool(false)
  170. int(50)
  171. bool(true)
  172. -- File content type : alphanumeric --
  173. -- fgets() with file pointer pointing at EOF --
  174. int(0)
  175. int(50)
  176. bool(false)
  177. bool(false)
  178. int(50)
  179. bool(true)
  180. -- Testing fgets() with file opened using mode a+b --
  181. -- File content type : numeric --
  182. -- fgets() with file pointer pointing at EOF --
  183. int(0)
  184. int(50)
  185. bool(false)
  186. bool(false)
  187. int(50)
  188. bool(true)
  189. -- File content type : text --
  190. -- fgets() with file pointer pointing at EOF --
  191. int(0)
  192. int(50)
  193. bool(false)
  194. bool(false)
  195. int(50)
  196. bool(true)
  197. -- File content type : text_with_new_line --
  198. -- fgets() with file pointer pointing at EOF --
  199. int(0)
  200. int(50)
  201. bool(false)
  202. bool(false)
  203. int(50)
  204. bool(true)
  205. -- File content type : alphanumeric --
  206. -- fgets() with file pointer pointing at EOF --
  207. int(0)
  208. int(50)
  209. bool(false)
  210. bool(false)
  211. int(50)
  212. bool(true)
  213. -- Testing fgets() with file opened using mode a+t --
  214. -- File content type : numeric --
  215. -- fgets() with file pointer pointing at EOF --
  216. int(0)
  217. int(50)
  218. bool(false)
  219. bool(false)
  220. int(50)
  221. bool(true)
  222. -- File content type : text --
  223. -- fgets() with file pointer pointing at EOF --
  224. int(0)
  225. int(50)
  226. bool(false)
  227. bool(false)
  228. int(50)
  229. bool(true)
  230. -- File content type : text_with_new_line --
  231. -- fgets() with file pointer pointing at EOF --
  232. int(0)
  233. int(50)
  234. bool(false)
  235. bool(false)
  236. int(50)
  237. bool(true)
  238. -- File content type : alphanumeric --
  239. -- fgets() with file pointer pointing at EOF --
  240. int(0)
  241. int(50)
  242. bool(false)
  243. bool(false)
  244. int(50)
  245. bool(true)
  246. -- Testing fgets() with file opened using mode x+ --
  247. -- File content type : numeric --
  248. -- fgets() with file pointer pointing at EOF --
  249. int(0)
  250. int(50)
  251. bool(false)
  252. bool(false)
  253. int(50)
  254. bool(true)
  255. -- File content type : text --
  256. -- fgets() with file pointer pointing at EOF --
  257. int(0)
  258. int(50)
  259. bool(false)
  260. bool(false)
  261. int(50)
  262. bool(true)
  263. -- File content type : text_with_new_line --
  264. -- fgets() with file pointer pointing at EOF --
  265. int(0)
  266. int(50)
  267. bool(false)
  268. bool(false)
  269. int(50)
  270. bool(true)
  271. -- File content type : alphanumeric --
  272. -- fgets() with file pointer pointing at EOF --
  273. int(0)
  274. int(50)
  275. bool(false)
  276. bool(false)
  277. int(50)
  278. bool(true)
  279. -- Testing fgets() with file opened using mode x+b --
  280. -- File content type : numeric --
  281. -- fgets() with file pointer pointing at EOF --
  282. int(0)
  283. int(50)
  284. bool(false)
  285. bool(false)
  286. int(50)
  287. bool(true)
  288. -- File content type : text --
  289. -- fgets() with file pointer pointing at EOF --
  290. int(0)
  291. int(50)
  292. bool(false)
  293. bool(false)
  294. int(50)
  295. bool(true)
  296. -- File content type : text_with_new_line --
  297. -- fgets() with file pointer pointing at EOF --
  298. int(0)
  299. int(50)
  300. bool(false)
  301. bool(false)
  302. int(50)
  303. bool(true)
  304. -- File content type : alphanumeric --
  305. -- fgets() with file pointer pointing at EOF --
  306. int(0)
  307. int(50)
  308. bool(false)
  309. bool(false)
  310. int(50)
  311. bool(true)
  312. -- Testing fgets() with file opened using mode x+t --
  313. -- File content type : numeric --
  314. -- fgets() with file pointer pointing at EOF --
  315. int(0)
  316. int(50)
  317. bool(false)
  318. bool(false)
  319. int(50)
  320. bool(true)
  321. -- File content type : text --
  322. -- fgets() with file pointer pointing at EOF --
  323. int(0)
  324. int(50)
  325. bool(false)
  326. bool(false)
  327. int(50)
  328. bool(true)
  329. -- File content type : text_with_new_line --
  330. -- fgets() with file pointer pointing at EOF --
  331. int(0)
  332. int(50)
  333. bool(false)
  334. bool(false)
  335. int(50)
  336. bool(true)
  337. -- File content type : alphanumeric --
  338. -- fgets() with file pointer pointing at EOF --
  339. int(0)
  340. int(50)
  341. bool(false)
  342. bool(false)
  343. int(50)
  344. bool(true)
  345. Done