import zend standard tests
[hiphop-php.git] / hphp / test / zend / bad / ext-standard-file / fgets_error.php
blob3128dee7417477d7bcf07ccdf3420a9a33facad8
1 <?php
2 /*
3 Prototype: string fgets ( resource $handle [, int $length] );
4 Description: Gets line from file pointer
5 */
7 echo "*** Testing error conditions ***\n";
8 // zero argument
9 echo "-- Testing fgets() with zero argument --\n";
10 var_dump( fgets() );
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";
19 $len = 0;
20 var_dump( fgets($fp, $len) );
21 $len = -10;
22 var_dump( fgets($fp, $len) );
23 $len = 1;
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 (
30 "string",
31 10,
32 10.5,
33 true,
34 array(1,2,3),
35 new stdclass,
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 --";
45 fclose($fp);
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));
53 echo "Done\n";