3 Prototype: string fgets ( resource $handle [, int $length] );
4 Description: Gets line from file pointer
7 echo "*** Testing error conditions ***\n";
9 echo "-- Testing fgets() with zero argument --\n";
12 // more than expected no. of args
13 echo "-- Testing fgets() with more than expected number of arguments --\n";
14 $fp = fopen(__FILE__
, "r");
15 var_dump( fgets($fp, 10, $fp) );
17 // invalid length argument
18 echo "-- Testing fgets() with invalid length arguments --\n";
20 var_dump( fgets($fp, $len) );
22 var_dump( fgets($fp, $len) );
24 var_dump( fgets($fp, $len) ); // return length - 1 always, expect false
27 // test invalid arguments : non-resources
28 echo "-- Testing fgets() with invalid arguments --\n";
29 $invalid_args = array (
37 /* loop to test fgets() with different invalid type of args */
38 for($loop_counter = 1; $loop_counter <= count($invalid_args); $loop_counter++
) {
39 echo "-- Iteration $loop_counter --\n";
40 var_dump( fgets($invalid_args[$loop_counter - 1], 10) );
43 // fgets() on a file handle which is already closed
44 echo "-- Testing fgets() with closed/unset file handle --";
46 var_dump(fgets($fp,10));
48 // fgets() on a file handle which is unset
49 $file_handle = fopen(__FILE__
, "r");
50 unset($file_handle); //unset file handle
51 var_dump( fgets(@$file_handle,10));