summaryrefslogtreecommitdiff
path: root/ext/standard/tests/file/fgetc_variation3.phpt
blob: 0d795688ad8fb05e922e1d987fdb44069efa416c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
--TEST--
Test fgetc() function : usage variations - write only modes (Bug #42036)
--FILE--
<?php
/*
 Prototype: string fgetc ( resource $handle );
 Description: Gets character from file pointer
*/

/* try fgetc on files which are opened in non readable modes
    w, wb, wt,
    a, ab, at,
    x, xb, xt
*/
// include the header for common test function
include ("file.inc");

echo "*** Testing fgetc() with file opened in write only mode ***\n";

$file_modes = array("w", "wb", "wt", "a", "ab", "at", "x", "xb", "xt");
$filename = dirname(__FILE__)."/fgetc_variation3.tmp";
foreach ($file_modes as $file_mode ) {
  echo "-- File opened in mode : $file_mode --\n";

  $file_handle = fopen($filename, $file_mode);
  if(!$file_handle) {
    echo "Error: failed to open file $filename!\n";
    exit();
  }
  $data = "fgetc_variation test";
  fwrite($file_handle, $data);

  // rewind the file pointer to beginning of the file
  var_dump( rewind($file_handle) );
  var_dump( ftell($file_handle) );
  var_dump( feof($file_handle) );

  // read from file
  var_dump( fgetc($file_handle) ); // expected : no chars should be read
  var_dump( ftell($file_handle) ); // ensure that file pointer position is not changed
  var_dump( feof($file_handle) ); // check if end of file pointer is set

  // close the file
  fclose($file_handle);

  // delete the file
  unlink($filename);
}

echo "Done\n";
?>
--EXPECTF--
*** Testing fgetc() with file opened in write only mode ***
-- File opened in mode : w --
bool(true)
int(0)
bool(false)
bool(false)
int(0)
bool(false)
-- File opened in mode : wb --
bool(true)
int(0)
bool(false)
bool(false)
int(0)
bool(false)
-- File opened in mode : wt --
bool(true)
int(0)
bool(false)
bool(false)
int(0)
bool(false)
-- File opened in mode : a --
bool(true)
int(0)
bool(false)
bool(false)
int(0)
bool(false)
-- File opened in mode : ab --
bool(true)
int(0)
bool(false)
bool(false)
int(0)
bool(false)
-- File opened in mode : at --
bool(true)
int(0)
bool(false)
bool(false)
int(0)
bool(false)
-- File opened in mode : x --
bool(true)
int(0)
bool(false)
bool(false)
int(0)
bool(false)
-- File opened in mode : xb --
bool(true)
int(0)
bool(false)
bool(false)
int(0)
bool(false)
-- File opened in mode : xt --
bool(true)
int(0)
bool(false)
bool(false)
int(0)
bool(false)
Done