1--TEST--
2Test fgets() function : error conditions
3--FILE--
4<?php
5echo "*** Testing error conditions ***\n";
6
7$fp = fopen(__FILE__, "r");
8
9// invalid length argument
10echo "-- Testing fgets() with invalid length arguments --\n";
11$len = 0;
12try {
13    var_dump( fgets($fp, $len) );
14} catch (\ValueError $e) {
15    echo $e->getMessage() . \PHP_EOL;
16}
17
18$len = -10;
19try {
20    var_dump( fgets($fp, $len) );
21} catch (\ValueError $e) {
22    echo $e->getMessage() . \PHP_EOL;
23}
24$len = 1;
25var_dump( fgets($fp, $len) ); // return length - 1 always, expect false
26
27?>
28--EXPECT--
29*** Testing error conditions ***
30-- Testing fgets() with invalid length arguments --
31fgets(): Argument #2 ($length) must be greater than 0
32fgets(): Argument #2 ($length) must be greater than 0
33bool(false)
34