1--TEST--
2Test fseek(), ftell() & rewind() functions : error conditions - fseek()
3--FILE--
4<?php
5
6/* Prototype: int fseek ( resource $handle, int $offset [, int $whence] );
7   Description: Seeks on a file pointer
8
9   Prototype: bool rewind ( resource $handle );
10   Description: Rewind the position of a file pointer
11
12   Prototype: int ftell ( resource $handle );
13   Description: Tells file pointer read/write position
14*/
15
16echo "*** Testing fseek() : error conditions ***\n";
17// zero argument
18echo "-- Testing fseek() with zero argument --\n";
19var_dump( fseek() );
20
21// unexpected no. of args
22echo "-- Testing fseek() with unexpected number of arguments --\n";
23$fp = fopen(__FILE__, "r");
24var_dump( fseek($fp) );
25var_dump( fseek($fp, 10, $fp,10) );
26
27// test invalid arguments : non-resources
28echo "-- Testing fseek() with invalid arguments --\n";
29$invalid_args = array (
30  "string",
31  10,
32  10.5,
33  true,
34  array(1,2,3),
35  new stdclass
36);
37/* loop to test fseek() with different invalid type of args */
38for($loop_counter = 1; $loop_counter <= count($invalid_args); $loop_counter++) {
39  echo "-- Iteration $loop_counter --\n";
40  var_dump( fseek($invalid_args[$loop_counter - 1], 10) );
41}
42
43// fseek() on a file handle which is already closed
44echo "-- Testing fseek() with closed/unset file handle --";
45fclose($fp);
46var_dump(fseek($fp,10));
47
48// fseek() on a file handle which is unset
49$file_handle = fopen(__FILE__, "r");
50unset($file_handle); //unset file handle
51var_dump( fseek(@$file_handle,10));
52
53echo "Done\n";
54?>
55--EXPECTF--
56*** Testing fseek() : error conditions ***
57-- Testing fseek() with zero argument --
58
59Warning: fseek() expects at least 2 parameters, 0 given in %s on line %d
60bool(false)
61-- Testing fseek() with unexpected number of arguments --
62
63Warning: fseek() expects at least 2 parameters, 1 given in %s on line %d
64bool(false)
65
66Warning: fseek() expects at most 3 parameters, 4 given in %s on line %d
67bool(false)
68-- Testing fseek() with invalid arguments --
69-- Iteration 1 --
70
71Warning: fseek() expects parameter 1 to be resource, string given in %s on line %d
72bool(false)
73-- Iteration 2 --
74
75Warning: fseek() expects parameter 1 to be resource, integer given in %s on line %d
76bool(false)
77-- Iteration 3 --
78
79Warning: fseek() expects parameter 1 to be resource, double given in %s on line %d
80bool(false)
81-- Iteration 4 --
82
83Warning: fseek() expects parameter 1 to be resource, boolean given in %s on line %d
84bool(false)
85-- Iteration 5 --
86
87Warning: fseek() expects parameter 1 to be resource, array given in %s on line %d
88bool(false)
89-- Iteration 6 --
90
91Warning: fseek() expects parameter 1 to be resource, object given in %s on line %d
92bool(false)
93-- Testing fseek() with closed/unset file handle --
94Warning: fseek(): %d is not a valid stream resource in %s on line %d
95bool(false)
96
97Warning: fseek() expects parameter 1 to be resource, null given in %s on line %d
98bool(false)
99Done
100