1--TEST--
2Test fwrite() function : error conditions
3--FILE--
4<?php
5// include the file.inc for Function: function delete_file($filename)
6include ("file.inc");
7
8echo "*** Testing fwrite() : error conditions ***\n";
9
10$filename = __DIR__."/fwrite_error.tmp";
11$file_handle  = fopen ( $filename, "w");
12$data = "data";
13
14// invalid length argument
15echo "-- Testing fwrite() with invalid length arguments --\n";
16$len = 0;
17var_dump( fwrite($file_handle, $data, $len) );
18$len = -10;
19var_dump( fwrite($file_handle, $data, $len) );
20
21// fwrite() on a file handle which is already closed
22echo "-- Testing fwrite() with closed/unset file handle --\n";
23fclose($file_handle);
24try {
25    var_dump(fwrite($file_handle,"data"));
26} catch (TypeError $e) {
27    echo $e->getMessage(), "\n";
28}
29
30echo "Done\n";
31?>
32--CLEAN--
33<?php
34$filename = __DIR__."/fwrite_error.tmp";
35unlink( $filename );
36?>
37--EXPECT--
38*** Testing fwrite() : error conditions ***
39-- Testing fwrite() with invalid length arguments --
40int(0)
41int(0)
42-- Testing fwrite() with closed/unset file handle --
43fwrite(): supplied resource is not a valid stream resource
44Done
45