![]() ![]() | ![]() |
1.1 misho 1: --TEST--
2: Test fseek() function : usage variations - different types for offset
3: --CREDITS--
4: Dave 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:
13: echo "*** Testing fseek() : usage variations ***\n";
14: error_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;
23: unset ($unset_var);
24:
25: class 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:
78: foreach($values as $value) {
1.1.1.2 ! misho 79: echo @"\nArg value $value \n";
1.1 misho 80: var_dump( fseek($fp, $value, $whence) );
81: var_dump( ftell($fp));
82: };
83: fclose($fp);
84:
85: echo "Done";
86: ?>
87: --EXPECTF--
88: *** Testing fseek() : usage variations ***
89:
90: Arg value 10.5
91: int(0)
92: int(10)
93:
94: Arg value -10.5
95: int(-1)
96: int(10)
97:
98: Arg value 1.07654321E-9
99: int(0)
100: int(0)
101:
102: Arg value 0.5
103: int(0)
104: int(0)
105:
106: Arg value Array
107:
108: Warning: fseek() expects parameter 2 to be long, array given in %s on line %d
109: bool(false)
110: int(0)
111:
112: Arg value Array
113:
114: Warning: fseek() expects parameter 2 to be long, array given in %s on line %d
115: bool(false)
116: int(0)
117:
118: Arg value Array
119:
120: Warning: fseek() expects parameter 2 to be long, array given in %s on line %d
121: bool(false)
122: int(0)
123:
124: Arg value Array
125:
126: Warning: fseek() expects parameter 2 to be long, array given in %s on line %d
127: bool(false)
128: int(0)
129:
130: Arg value Array
131:
132: Warning: fseek() expects parameter 2 to be long, array given in %s on line %d
133: bool(false)
134: int(0)
135:
136: Arg value
137: int(0)
138: int(0)
139:
140: Arg value
141: int(0)
142: int(0)
143:
144: Arg value 1
145: int(0)
146: int(1)
147:
148: Arg value
149: int(0)
150: int(0)
151:
152: Arg value 1
153: int(0)
154: int(1)
155:
156: Arg value
157: int(0)
158: int(0)
159:
160: Arg value
161:
162: Warning: fseek() expects parameter 2 to be long, string given in %s on line %d
163: bool(false)
164: int(0)
165:
166: Arg value
167:
168: Warning: fseek() expects parameter 2 to be long, string given in %s on line %d
169: bool(false)
170: int(0)
171:
172: Arg value string
173:
174: Warning: fseek() expects parameter 2 to be long, string given in %s on line %d
175: bool(false)
176: int(0)
177:
178: Arg value string
179:
180: Warning: fseek() expects parameter 2 to be long, string given in %s on line %d
181: bool(false)
182: int(0)
183:
184: Arg value testClass
185:
186: Warning: fseek() expects parameter 2 to be long, object given in %s on line %d
187: bool(false)
188: int(0)
189:
190: Arg value
191: int(0)
192: int(0)
193:
194: Arg value
195: int(0)
196: int(0)
197: Done
198: