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