1--TEST--
2Test fseek() function : usage variations  - different types for offset
3--CREDITS--
4Dave Kelsey <d_kelsey@uk.ibm.com>
5--FILE--
6<?php
7/* Prototype  : proto int fseek(resource fp, int offset [, int whence])
8 * Description: Seek on a file pointer
9 * Source code: ext/standard/file.c
10 * Alias to functions: gzseek
11 */
12
13echo "*** Testing fseek() : usage variations ***\n";
14error_reporting(E_ALL & ~E_NOTICE);
15
16// Initialise function arguments not being substituted (if any)
17
18$fp = fopen(__FILE__, 'r');
19$whence = SEEK_SET;
20
21//get an unset variable
22$unset_var = 10;
23unset ($unset_var);
24
25class testClass {
26   public function __toString() {
27      return "testClass";
28   }
29}
30
31
32//array of values to iterate over
33$values = array(
34
35      // float data
36      10.5,
37      -10.5,
38      10.7654321E-10,
39      .5,
40
41      // array data
42      array(),
43      array(0),
44      array(1),
45      array(1, 2),
46      array('color' => 'red', 'item' => 'pen'),
47
48      // null data
49      NULL,
50      null,
51
52      // boolean data
53      true,
54      false,
55      TRUE,
56      FALSE,
57
58      // empty data
59      "",
60      '',
61
62      // string data
63      "string",
64      'string',
65
66      // object data
67      new testClass(),
68
69      // undefined data
70      $undefined_var,
71
72      // unset data
73      $unset_var,
74);
75
76// loop through each element of the array for offset
77
78foreach($values as $value) {
79      echo @"\nArg value $value \n";
80      var_dump( fseek($fp, $value, $whence) );
81      var_dump( ftell($fp));
82};
83fclose($fp);
84
85echo "Done";
86?>
87--EXPECTF--
88*** Testing fseek() : usage variations ***
89
90Arg value 10.5
91int(0)
92int(10)
93
94Arg value -10.5
95int(-1)
96int(10)
97
98Arg value 1.07654321E-9
99int(0)
100int(0)
101
102Arg value 0.5
103int(0)
104int(0)
105
106Arg value Array
107
108Warning: fseek() expects parameter 2 to be long, array given in %s on line %d
109bool(false)
110int(0)
111
112Arg value Array
113
114Warning: fseek() expects parameter 2 to be long, array given in %s on line %d
115bool(false)
116int(0)
117
118Arg value Array
119
120Warning: fseek() expects parameter 2 to be long, array given in %s on line %d
121bool(false)
122int(0)
123
124Arg value Array
125
126Warning: fseek() expects parameter 2 to be long, array given in %s on line %d
127bool(false)
128int(0)
129
130Arg value Array
131
132Warning: fseek() expects parameter 2 to be long, array given in %s on line %d
133bool(false)
134int(0)
135
136Arg value
137int(0)
138int(0)
139
140Arg value
141int(0)
142int(0)
143
144Arg value 1
145int(0)
146int(1)
147
148Arg value
149int(0)
150int(0)
151
152Arg value 1
153int(0)
154int(1)
155
156Arg value
157int(0)
158int(0)
159
160Arg value
161
162Warning: fseek() expects parameter 2 to be long, string given in %s on line %d
163bool(false)
164int(0)
165
166Arg value
167
168Warning: fseek() expects parameter 2 to be long, string given in %s on line %d
169bool(false)
170int(0)
171
172Arg value string
173
174Warning: fseek() expects parameter 2 to be long, string given in %s on line %d
175bool(false)
176int(0)
177
178Arg value string
179
180Warning: fseek() expects parameter 2 to be long, string given in %s on line %d
181bool(false)
182int(0)
183
184Arg value testClass
185
186Warning: fseek() expects parameter 2 to be long, object given in %s on line %d
187bool(false)
188int(0)
189
190Arg value
191int(0)
192int(0)
193
194Arg value
195int(0)
196int(0)
197Done
198
199