1--TEST--
2Test fgets() function : usage variations - closed handle
3--FILE--
4<?php
5/*
6 Prototype: string fgets ( resource $handle [, int $length] );
7 Description: Gets a line from file pointer
8*/
9
10/* try reading a line using fgets() using invalid handles
11    - closed file handle
12    - unset file handle
13*/
14
15// include the header for common test function
16include ("file.inc");
17
18echo "*** Testing fgets() : usage variations ***\n";
19
20echo "-- Testing fgets() with closed handle --\n";
21// open the file for reading
22$file_handle = fopen(__FILE__, "r");
23// close the file
24fclose($file_handle);
25
26// read from closed file
27var_dump( fgets($file_handle) ); // default length
28var_dump( fgets($file_handle, 10) ); // with specific length
29
30echo "-- Testing fgets() with unset handle --\n";
31// open the file for reading
32$file_handle = fopen(__FILE__, "r");
33// unset the file handle
34unset($file_handle);
35
36//fgets using unset handle
37var_dump( fgets($file_handle) ); // default length
38var_dump( fgets($file_handle, 10) ); // with specific length
39
40echo "Done";
41?>
42--EXPECTF--
43*** Testing fgets() : usage variations ***
44-- Testing fgets() with closed handle --
45
46Warning: fgets(): supplied resource is not a valid stream resource in %s on line %d
47bool(false)
48
49Warning: fgets(): supplied resource is not a valid stream resource in %s on line %d
50bool(false)
51-- Testing fgets() with unset handle --
52
53Notice: Undefined variable: file_handle in %s on line %d
54
55Warning: fgets() expects parameter 1 to be resource, null given in %s on line %d
56bool(false)
57
58Notice: Undefined variable: file_handle in %s on line %d
59
60Warning: fgets() expects parameter 1 to be resource, null given in %s on line %d
61bool(false)
62Done
63