xref: /PHP-7.2/ext/standard/tests/file/fscanf.phpt (revision 17ccbeec)
1--TEST--
2fscanf() tests
3--FILE--
4<?php
5
6$filename = dirname(__FILE__)."/fscanf.dat";
7
8var_dump(fscanf());
9var_dump(fscanf(array()));
10var_dump(fscanf(array(), array()));
11
12file_put_contents($filename, "data");
13
14$fp = fopen($filename, "rt");
15var_dump(fscanf($fp, "%d", $v));
16var_dump($v);
17fclose($fp);
18
19$fp = fopen($filename, "rt");
20var_dump(fscanf($fp, "%s", $v));
21var_dump($v);
22fclose($fp);
23
24$fp = fopen($filename, "rt");
25var_dump(fscanf($fp, "%s", $v, $v1));
26var_dump($v);
27var_dump($v1);
28fclose($fp);
29
30$v = array();
31$v1 = array();
32$fp = fopen($filename, "rt");
33var_dump(fscanf($fp, "", $v, $v1));
34var_dump($v);
35var_dump($v1);
36fclose($fp);
37
38$v = array();
39$v1 = array();
40$fp = fopen($filename, "rt");
41var_dump(fscanf($fp, "%.a", $v, $v1));
42var_dump($v);
43var_dump($v1);
44fclose($fp);
45
46@unlink($filename);
47touch($filename);
48
49$fp = fopen($filename, "rt");
50var_dump(fscanf($fp, "%s", $v));
51var_dump($v);
52fclose($fp);
53
54file_put_contents($filename, "data");
55
56$fp = fopen($filename, "rt");
57var_dump(fscanf($fp, "%s%d", $v));
58
59echo "Done\n";
60?>
61--CLEAN--
62<?php
63$filename = dirname(__FILE__)."/fscanf.dat";
64unlink($filename);
65?>
66--EXPECTF--
67Warning: fscanf() expects at least 2 parameters, 0 given in %s on line %d
68NULL
69
70Warning: fscanf() expects at least 2 parameters, 1 given in %s on line %d
71NULL
72
73Warning: fscanf() expects parameter 1 to be resource, array given in %s on line %d
74NULL
75int(0)
76NULL
77int(1)
78string(4) "data"
79
80Warning: fscanf(): Variable is not assigned by any conversion specifiers in %s on line %d
81int(-1)
82string(4) "data"
83NULL
84
85Warning: fscanf(): Variable is not assigned by any conversion specifiers in %s on line %d
86int(-1)
87array(0) {
88}
89array(0) {
90}
91
92Warning: fscanf(): Bad scan conversion character "." in %s on line %d
93int(-1)
94array(0) {
95}
96array(0) {
97}
98bool(false)
99array(0) {
100}
101
102Warning: fscanf(): Different numbers of variable names and field specifiers in %s on line %d
103int(-1)
104Done
105