1--TEST--
2Test fgetc() function : usage variations - read when file pointer at EOF
3--FILE--
4<?php
5// include the header for common test function
6include ("file.inc");
7
8echo "*** Testing fgetc() : usage variations ***\n";
9echo "-- Testing fgetc() with file whose file pointer is pointing to EOF --\n";
10// create a file
11create_files(__DIR__, 1, "text_with_new_line", 0755, 1, "w", "fgetc_variation");
12
13$filename = __DIR__."/fgetc_variation1.tmp";
14
15// loop to check the file opened in different read modes
16$file_modes = array("r", "rb", "rt", "r+", "r+b", "r+t");
17$loop_counter =0;
18for(; $loop_counter < count($file_modes); $loop_counter++) {
19  // print the hearder
20  echo "-- File opened in mode : $file_modes[$loop_counter] --\n";
21  // open the file
22  $file_handle = fopen ($filename, $file_modes[$loop_counter]);
23  if (!$file_handle) {
24    echo "Error: failed to open file $filename! \n";
25    exit();
26  }
27
28  // seek to end of the file and try fgetc()
29  var_dump( fseek($file_handle, 0, SEEK_END) ); // set file pointer to eof
30  var_dump( feof($file_handle) );  // expected false
31  var_dump( ftell($file_handle) );  // ensure that file pointer is at eof
32  var_dump( fgetc($file_handle) ); // try n read a char, none expected
33  var_dump( feof($file_handle) ); // ensure that file pointer is at eof
34  var_dump( ftell($file_handle) ); // file pointer position
35
36  // close the file handle
37  fclose($file_handle);
38}
39echo "Done\n";
40?>
41--CLEAN--
42<?php
43unlink( __DIR__."/fgetc_variation1.tmp");
44?>
45--EXPECT--
46*** Testing fgetc() : usage variations ***
47-- Testing fgetc() with file whose file pointer is pointing to EOF --
48-- File opened in mode : r --
49int(0)
50bool(false)
51int(1024)
52bool(false)
53bool(true)
54int(1024)
55-- File opened in mode : rb --
56int(0)
57bool(false)
58int(1024)
59bool(false)
60bool(true)
61int(1024)
62-- File opened in mode : rt --
63int(0)
64bool(false)
65int(1024)
66bool(false)
67bool(true)
68int(1024)
69-- File opened in mode : r+ --
70int(0)
71bool(false)
72int(1024)
73bool(false)
74bool(true)
75int(1024)
76-- File opened in mode : r+b --
77int(0)
78bool(false)
79int(1024)
80bool(false)
81bool(true)
82int(1024)
83-- File opened in mode : r+t --
84int(0)
85bool(false)
86int(1024)
87bool(false)
88bool(true)
89int(1024)
90Done
91