1--TEST--
2Test fpassthru() function: Variations
3--FILE--
4<?php
5/*
6Prototype: int fpassthru ( resource $handle );
7Description: Reads to EOF on the given file pointer from the current position
8  and writes the results to the output buffer.
9*/
10
11echo "*** Testing fpassthru() function with files ***\n\n";
12
13echo "--- Testing with different offsets ---\n";
14
15$file_name = dirname(__FILE__)."/passthru_variation.tmp";
16$file_write = fopen($file_name, "w");
17fwrite($file_write, "1234567890abcdefghijklmnopqrstuvwxyz");
18fclose($file_write);
19
20$file_read = fopen($file_name, "r");
21
22$offset_arr = array(
23  /* Positive offsets */
24  0,
25  1,
26  5,
27  10,
28  20,
29  30,
30  35,
31  36,
32  70,
33  /* Negative offsets, the file pointer should be at the end of file
34  to get data */
35  -1,
36  -5,
37  -10,
38  -20,
39  -35,
40  -36,
41  -70
42);
43
44for( $i=0; $i<count($offset_arr); $i++ ) {
45  echo "-- Iteration $i --\n";
46  if( $offset_arr[$i] >= 0 ) {
47    fseek($file_read, $offset_arr[$i], SEEK_SET);
48    var_dump(fpassthru($file_read) );
49    rewind( $file_read );
50  }else
51    {
52      fseek($file_read, $offset_arr[$i], SEEK_END);
53      var_dump( fpassthru($file_read) );
54      rewind( $file_read );
55    }
56}
57
58fclose($file_read);  // closing the handle
59
60echo "\n--- Testing with binary mode file ---\n";
61/* Opening the file in binary read mode */
62$file_read = fopen($file_name, "rb");
63
64fseek($file_read, 12, SEEK_SET);
65var_dump(fpassthru($file_read) );
66rewind( $file_read );
67fclose($file_read);
68
69unlink($file_name);
70
71echo "\n*** Done ***\n";
72
73?>
74--EXPECTF--
75*** Testing fpassthru() function with files ***
76
77--- Testing with different offsets ---
78-- Iteration 0 --
791234567890abcdefghijklmnopqrstuvwxyzint(36)
80-- Iteration 1 --
81234567890abcdefghijklmnopqrstuvwxyzint(35)
82-- Iteration 2 --
8367890abcdefghijklmnopqrstuvwxyzint(31)
84-- Iteration 3 --
85abcdefghijklmnopqrstuvwxyzint(26)
86-- Iteration 4 --
87klmnopqrstuvwxyzint(16)
88-- Iteration 5 --
89uvwxyzint(6)
90-- Iteration 6 --
91zint(1)
92-- Iteration 7 --
93int(0)
94-- Iteration 8 --
95int(0)
96-- Iteration 9 --
97zint(1)
98-- Iteration 10 --
99vwxyzint(5)
100-- Iteration 11 --
101qrstuvwxyzint(10)
102-- Iteration 12 --
103ghijklmnopqrstuvwxyzint(20)
104-- Iteration 13 --
105234567890abcdefghijklmnopqrstuvwxyzint(35)
106-- Iteration 14 --
1071234567890abcdefghijklmnopqrstuvwxyzint(36)
108-- Iteration 15 --
1091234567890abcdefghijklmnopqrstuvwxyzint(36)
110
111--- Testing with binary mode file ---
112cdefghijklmnopqrstuvwxyzint(24)
113
114*** Done ***
115