summaryrefslogtreecommitdiff
path: root/ext/standard/tests/file/007_error.phpt
blob: 8b0d07af8faffeed5ccd801c83b9884e49773978 (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
--TEST--
Test fopen, fclose() & feof() functions: error conditions
--FILE--
<?php
/*
 Prototype: resource fopen(string $filename, string $mode
                            [, bool $use_include_path [, resource $context]] );
 Description: Opens file or URL.

 Prototype: bool fclose ( resource $handle );
 Description: Closes an open file pointer

 Prototype: bool feof ( resource $handle )
 Description: Returns TRUE if the file pointer is at EOF or an error occurs 
   (including socket timeout); otherwise returns FALSE. 
*/

echo "*** Testing error conditions for fopen(), fclsoe() & feof() ***\n";
/* Arguments less than minimum no.of args */

// fopen ()
var_dump(fopen(__FILE__)); // one valid argument
var_dump(fopen());  // zero argument

// fclose()
$fp = fopen(__FILE__, "r");
fclose($fp);
var_dump( fclose($fp) ); // closed handle
var_dump( fclose(__FILE__) ); // invalid handle
var_dump( fclose() ); // zero argument 

//feof()
var_dump( feof($fp) );  // closed handle
var_dump( feof(__FILE__) );  // invalid handle
var_dump( feof() );  //zero argument

/* Arguments greater than maximum no.of ags */
var_dump(fopen(__FILE__, "r", TRUE, "www.example.com", 100));

$fp = fopen(__FILE__, "r");
var_dump( fclose($fp, "handle") );

var_dump( feof($fp, "handle"));
fclose($fp);

/* test invalid arguments : non-resources */
chdir(dirname(__FILE__));
echo "-- Testing fopen(), fclose() & feof() with invalid arguments --\n";
$invalid_args = array (
  "string",
  10,
  10.5,
  true,
  array(1,2,3),
  NULL,
  ""
);

/* loop to test fclose with different invalid type of args */
for($loop_counter = 1; $loop_counter <= count($invalid_args); $loop_counter++) {
  echo "-- Iteration $loop_counter --\n";
  var_dump( fopen($invalid_args[$loop_counter - 1], "r") );
  var_dump( fclose($invalid_args[$loop_counter - 1]) );
  var_dump( feof($invalid_args[$loop_counter - 1]) );
}

?>
--EXPECTF--
*** Testing error conditions for fopen(), fclsoe() & feof() ***

Warning: fopen() expects at least 2 parameters, 1 given in %s on line %d
bool(false)

Warning: fopen() expects at least 2 parameters, 0 given in %s on line %d
bool(false)

Warning: fclose(): 5 is not a valid stream resource in %s on line %d
bool(false)

Warning: fclose(): supplied argument is not a valid stream resource in %s on line %d
bool(false)

Warning: Wrong parameter count for fclose() in %s on line %d
NULL

Warning: feof(): 5 is not a valid stream resource in %s on line %d
bool(false)

Warning: feof(): supplied argument is not a valid stream resource in %s on line %d
bool(false)

Warning: Wrong parameter count for feof() in %s on line %d
NULL

Warning: fopen() expects at most 4 parameters, 5 given in %s on line %d
bool(false)

Warning: Wrong parameter count for fclose() in %s on line %d
NULL

Warning: Wrong parameter count for feof() in %s on line %d
NULL
-- Testing fopen(), fclose() & feof() with invalid arguments --
-- Iteration 1 --

Warning: fopen(string): failed to open stream: No such file or directory in %s on line %d
bool(false)

Warning: fclose(): supplied argument is not a valid stream resource in %s on line %d
bool(false)

Warning: feof(): supplied argument is not a valid stream resource in %s on line %d
bool(false)
-- Iteration 2 --

Warning: fopen(10): failed to open stream: No such file or directory in %s on line %d
bool(false)

Warning: fclose(): supplied argument is not a valid stream resource in %s on line %d
bool(false)

Warning: feof(): supplied argument is not a valid stream resource in %s on line %d
bool(false)
-- Iteration 3 --

Warning: fopen(10.5): failed to open stream: No such file or directory in %s on line %d
bool(false)

Warning: fclose(): supplied argument is not a valid stream resource in %s on line %d
bool(false)

Warning: feof(): supplied argument is not a valid stream resource in %s on line %d
bool(false)
-- Iteration 4 --

Warning: fopen(1): failed to open stream: No such file or directory in %s on line %d
bool(false)

Warning: fclose(): supplied argument is not a valid stream resource in %s on line %d
bool(false)

Warning: feof(): supplied argument is not a valid stream resource in %s on line %d
bool(false)
-- Iteration 5 --

Notice: Array to string conversion in %s on line %d

Warning: fopen(Array): failed to open stream: No such file or directory in %s on line %d
bool(false)

Warning: fclose(): supplied argument is not a valid stream resource in %s on line %d
bool(false)

Warning: feof(): supplied argument is not a valid stream resource in %s on line %d
bool(false)
-- Iteration 6 --
bool(false)

Warning: fclose(): supplied argument is not a valid stream resource in %s on line %d
bool(false)

Warning: feof(): supplied argument is not a valid stream resource in %s on line %d
bool(false)
-- Iteration 7 --
bool(false)

Warning: fclose(): supplied argument is not a valid stream resource in %s on line %d
bool(false)

Warning: feof(): supplied argument is not a valid stream resource in %s on line %d
bool(false)