007_basic.phpt 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. --TEST--
  2. Test fopen(), fclose() & feof() functions: basic functionality
  3. --FILE--
  4. <?php
  5. /*
  6. Prototype: resource fopen(string $filename, string $mode
  7. [, bool $use_include_path [, resource $context]] );
  8. Description: Opens file or URL.
  9. Prototype: bool fclose ( resource $handle );
  10. Description: Closes an open file pointer
  11. Prototype: bool feof ( resource $handle );
  12. Description: Tests for end-of-file on a file pointer
  13. */
  14. echo "*** Testing basic operations of fopen() and fclose() functions ***\n";
  15. $modes = array(
  16. "w",
  17. "wb",
  18. "wt",
  19. "w+",
  20. "w+b",
  21. "w+t",
  22. "r",
  23. "rb",
  24. "rt",
  25. "r+",
  26. "r+b",
  27. "r+t",
  28. "a",
  29. "ab",
  30. "at",
  31. "a+",
  32. "a+t",
  33. "a+b"
  34. );
  35. for( $i=0; $i<count($modes); $i++ ) {
  36. echo "\n-- Iteration with mode '$modes[$i]' --\n";
  37. $filename = dirname(__FILE__)."/007_basic.tmp";
  38. // check fopen()
  39. $handle = fopen($filename, $modes[$i]);
  40. var_dump($handle );
  41. var_dump( ftell($handle) );
  42. var_dump( feof($handle) );
  43. // check fclose()
  44. var_dump( fclose($handle) );
  45. var_dump( $handle );
  46. // confirm the closure, using ftell() and feof(), expect, false
  47. var_dump( ftell($handle) );
  48. var_dump( feof($handle) );
  49. }
  50. // remove the temp file
  51. unlink($filename);
  52. $x_modes = array(
  53. "x",
  54. "xb",
  55. "xt",
  56. "x+",
  57. "x+b",
  58. "x+t"
  59. );
  60. for( $i=0; $i<count($x_modes); $i++ ) {
  61. echo "\n-- Iteration with mode '$x_modes[$i]' --\n";
  62. $handle = fopen($filename, $x_modes[$i]);
  63. var_dump($handle );
  64. var_dump( ftell($handle) );
  65. var_dump( feof($handle) );
  66. // check fclose()
  67. var_dump( fclose($handle) );
  68. var_dump( $handle );
  69. // confirm the closure, using ftell() and feof(), expect, false
  70. var_dump( ftell($handle) );
  71. var_dump( feof($handle) );
  72. var_dump( $handle );
  73. // remove the file
  74. unlink( $filename );
  75. }
  76. echo "\n*** Done ***\n";
  77. --EXPECTF--
  78. *** Testing basic operations of fopen() and fclose() functions ***
  79. -- Iteration with mode 'w' --
  80. resource(%d) of type (stream)
  81. int(0)
  82. bool(false)
  83. bool(true)
  84. resource(%d) of type (Unknown)
  85. Warning: ftell(): %d is not a valid stream resource in %s on line %d
  86. bool(false)
  87. Warning: feof(): %d is not a valid stream resource in %s on line %d
  88. bool(false)
  89. -- Iteration with mode 'wb' --
  90. resource(%d) of type (stream)
  91. int(0)
  92. bool(false)
  93. bool(true)
  94. resource(%d) of type (Unknown)
  95. Warning: ftell(): %d is not a valid stream resource in %s on line %d
  96. bool(false)
  97. Warning: feof(): %d is not a valid stream resource in %s on line %d
  98. bool(false)
  99. -- Iteration with mode 'wt' --
  100. resource(%d) of type (stream)
  101. int(0)
  102. bool(false)
  103. bool(true)
  104. resource(%d) of type (Unknown)
  105. Warning: ftell(): %d is not a valid stream resource in %s on line %d
  106. bool(false)
  107. Warning: feof(): %d is not a valid stream resource in %s on line %d
  108. bool(false)
  109. -- Iteration with mode 'w+' --
  110. resource(%d) of type (stream)
  111. int(0)
  112. bool(false)
  113. bool(true)
  114. resource(%d) of type (Unknown)
  115. Warning: ftell(): %d is not a valid stream resource in %s on line %d
  116. bool(false)
  117. Warning: feof(): %d is not a valid stream resource in %s on line %d
  118. bool(false)
  119. -- Iteration with mode 'w+b' --
  120. resource(%d) of type (stream)
  121. int(0)
  122. bool(false)
  123. bool(true)
  124. resource(%d) of type (Unknown)
  125. Warning: ftell(): %d is not a valid stream resource in %s on line %d
  126. bool(false)
  127. Warning: feof(): %d is not a valid stream resource in %s on line %d
  128. bool(false)
  129. -- Iteration with mode 'w+t' --
  130. resource(%d) of type (stream)
  131. int(0)
  132. bool(false)
  133. bool(true)
  134. resource(%d) of type (Unknown)
  135. Warning: ftell(): %d is not a valid stream resource in %s on line %d
  136. bool(false)
  137. Warning: feof(): %d is not a valid stream resource in %s on line %d
  138. bool(false)
  139. -- Iteration with mode 'r' --
  140. resource(%d) of type (stream)
  141. int(0)
  142. bool(false)
  143. bool(true)
  144. resource(%d) of type (Unknown)
  145. Warning: ftell(): %d is not a valid stream resource in %s on line %d
  146. bool(false)
  147. Warning: feof(): %d is not a valid stream resource in %s on line %d
  148. bool(false)
  149. -- Iteration with mode 'rb' --
  150. resource(%d) of type (stream)
  151. int(0)
  152. bool(false)
  153. bool(true)
  154. resource(%d) of type (Unknown)
  155. Warning: ftell(): %d is not a valid stream resource in %s on line %d
  156. bool(false)
  157. Warning: feof(): %d is not a valid stream resource in %s on line %d
  158. bool(false)
  159. -- Iteration with mode 'rt' --
  160. resource(%d) of type (stream)
  161. int(0)
  162. bool(false)
  163. bool(true)
  164. resource(%d) of type (Unknown)
  165. Warning: ftell(): %d is not a valid stream resource in %s on line %d
  166. bool(false)
  167. Warning: feof(): %d is not a valid stream resource in %s on line %d
  168. bool(false)
  169. -- Iteration with mode 'r+' --
  170. resource(%d) of type (stream)
  171. int(0)
  172. bool(false)
  173. bool(true)
  174. resource(%d) of type (Unknown)
  175. Warning: ftell(): %d is not a valid stream resource in %s on line %d
  176. bool(false)
  177. Warning: feof(): %d is not a valid stream resource in %s on line %d
  178. bool(false)
  179. -- Iteration with mode 'r+b' --
  180. resource(%d) of type (stream)
  181. int(0)
  182. bool(false)
  183. bool(true)
  184. resource(%d) of type (Unknown)
  185. Warning: ftell(): %d is not a valid stream resource in %s on line %d
  186. bool(false)
  187. Warning: feof(): %d is not a valid stream resource in %s on line %d
  188. bool(false)
  189. -- Iteration with mode 'r+t' --
  190. resource(%d) of type (stream)
  191. int(0)
  192. bool(false)
  193. bool(true)
  194. resource(%d) of type (Unknown)
  195. Warning: ftell(): %d is not a valid stream resource in %s on line %d
  196. bool(false)
  197. Warning: feof(): %d is not a valid stream resource in %s on line %d
  198. bool(false)
  199. -- Iteration with mode 'a' --
  200. resource(%d) of type (stream)
  201. int(0)
  202. bool(false)
  203. bool(true)
  204. resource(%d) of type (Unknown)
  205. Warning: ftell(): %d is not a valid stream resource in %s on line %d
  206. bool(false)
  207. Warning: feof(): %d is not a valid stream resource in %s on line %d
  208. bool(false)
  209. -- Iteration with mode 'ab' --
  210. resource(%d) of type (stream)
  211. int(0)
  212. bool(false)
  213. bool(true)
  214. resource(%d) of type (Unknown)
  215. Warning: ftell(): %d is not a valid stream resource in %s on line %d
  216. bool(false)
  217. Warning: feof(): %d is not a valid stream resource in %s on line %d
  218. bool(false)
  219. -- Iteration with mode 'at' --
  220. resource(%d) of type (stream)
  221. int(0)
  222. bool(false)
  223. bool(true)
  224. resource(%d) of type (Unknown)
  225. Warning: ftell(): %d is not a valid stream resource in %s on line %d
  226. bool(false)
  227. Warning: feof(): %d is not a valid stream resource in %s on line %d
  228. bool(false)
  229. -- Iteration with mode 'a+' --
  230. resource(%d) of type (stream)
  231. int(0)
  232. bool(false)
  233. bool(true)
  234. resource(%d) of type (Unknown)
  235. Warning: ftell(): %d is not a valid stream resource in %s on line %d
  236. bool(false)
  237. Warning: feof(): %d is not a valid stream resource in %s on line %d
  238. bool(false)
  239. -- Iteration with mode 'a+t' --
  240. resource(%d) of type (stream)
  241. int(0)
  242. bool(false)
  243. bool(true)
  244. resource(%d) of type (Unknown)
  245. Warning: ftell(): %d is not a valid stream resource in %s on line %d
  246. bool(false)
  247. Warning: feof(): %d is not a valid stream resource in %s on line %d
  248. bool(false)
  249. -- Iteration with mode 'a+b' --
  250. resource(%d) of type (stream)
  251. int(0)
  252. bool(false)
  253. bool(true)
  254. resource(%d) of type (Unknown)
  255. Warning: ftell(): %d is not a valid stream resource in %s on line %d
  256. bool(false)
  257. Warning: feof(): %d is not a valid stream resource in %s on line %d
  258. bool(false)
  259. -- Iteration with mode 'x' --
  260. resource(%d) of type (stream)
  261. int(0)
  262. bool(false)
  263. bool(true)
  264. resource(%d) of type (Unknown)
  265. Warning: ftell(): %d is not a valid stream resource in %s on line %d
  266. bool(false)
  267. Warning: feof(): %d is not a valid stream resource in %s on line %d
  268. bool(false)
  269. resource(%d) of type (Unknown)
  270. -- Iteration with mode 'xb' --
  271. resource(%d) of type (stream)
  272. int(0)
  273. bool(false)
  274. bool(true)
  275. resource(%d) of type (Unknown)
  276. Warning: ftell(): %d is not a valid stream resource in %s on line %d
  277. bool(false)
  278. Warning: feof(): %d is not a valid stream resource in %s on line %d
  279. bool(false)
  280. resource(%d) of type (Unknown)
  281. -- Iteration with mode 'xt' --
  282. resource(%d) of type (stream)
  283. int(0)
  284. bool(false)
  285. bool(true)
  286. resource(%d) of type (Unknown)
  287. Warning: ftell(): %d is not a valid stream resource in %s on line %d
  288. bool(false)
  289. Warning: feof(): %d is not a valid stream resource in %s on line %d
  290. bool(false)
  291. resource(%d) of type (Unknown)
  292. -- Iteration with mode 'x+' --
  293. resource(%d) of type (stream)
  294. int(0)
  295. bool(false)
  296. bool(true)
  297. resource(%d) of type (Unknown)
  298. Warning: ftell(): %d is not a valid stream resource in %s on line %d
  299. bool(false)
  300. Warning: feof(): %d is not a valid stream resource in %s on line %d
  301. bool(false)
  302. resource(%d) of type (Unknown)
  303. -- Iteration with mode 'x+b' --
  304. resource(%d) of type (stream)
  305. int(0)
  306. bool(false)
  307. bool(true)
  308. resource(%d) of type (Unknown)
  309. Warning: ftell(): %d is not a valid stream resource in %s on line %d
  310. bool(false)
  311. Warning: feof(): %d is not a valid stream resource in %s on line %d
  312. bool(false)
  313. resource(%d) of type (Unknown)
  314. -- Iteration with mode 'x+t' --
  315. resource(%d) of type (stream)
  316. int(0)
  317. bool(false)
  318. bool(true)
  319. resource(%d) of type (Unknown)
  320. Warning: ftell(): %d is not a valid stream resource in %s on line %d
  321. bool(false)
  322. Warning: feof(): %d is not a valid stream resource in %s on line %d
  323. bool(false)
  324. resource(%d) of type (Unknown)
  325. *** Done ***