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