xref: /PHP-7.4/ext/standard/tests/file/fwrite.phpt (revision 1cbcf0f4)
1--TEST--
2fwrite() tests
3--FILE--
4<?php
5
6$filename = __DIR__."/fwrite.dat";
7
8$fp = fopen($filename, "w");
9var_dump(fwrite($fp));
10var_dump(fwrite($fp, array()));
11fclose($fp);
12
13$fp = fopen($filename, "r");
14var_dump(fwrite($fp, "data"));
15
16$fp = fopen($filename, "w");
17var_dump(fwrite($fp, "data", -1));
18var_dump(fwrite($fp, "data", 100000));
19fclose($fp);
20
21var_dump(fwrite($fp, "data", -1));
22
23var_dump(fwrite(array(), "data", -1));
24var_dump(fwrite(array(), "data"));
25var_dump(fwrite(array()));
26
27var_dump(file_get_contents($filename));
28
29@unlink($filename);
30echo "Done\n";
31?>
32--EXPECTF--
33Warning: fwrite() expects at least 2 parameters, 1 given in %s on line %d
34bool(false)
35
36Warning: fwrite() expects parameter 2 to be string, array given in %s on line %d
37bool(false)
38
39Notice: fwrite(): write of 4 bytes failed with errno=9 Bad file descriptor in %s on line %d
40bool(false)
41int(0)
42int(4)
43int(0)
44
45Warning: fwrite() expects parameter 1 to be resource, array given in %s on line %d
46bool(false)
47
48Warning: fwrite() expects parameter 1 to be resource, array given in %s on line %d
49bool(false)
50
51Warning: fwrite() expects at least 2 parameters, 1 given in %s on line %d
52bool(false)
53string(4) "data"
54Done
55