1--TEST--
2Test fgetc() function : error conditions
3--FILE--
4<?php
5/*
6 Prototype: string fgetc ( resource $handle );
7 Description: Gets character from file pointer
8*/
9
10echo "*** Testing error conditions ***\n";
11// zero argument
12echo "-- Testing fgetc() with zero argument --\n";
13var_dump( fgetc() );
14
15// more than expected no. of args
16echo "-- Testing fgetc() with more than expected number of arguments --\n";
17$fp = fopen(__FILE__, "r");
18var_dump( fgetc($fp, $fp) );
19fclose($fp);
20
21// test invalid arguments : non-resources
22echo "-- Testing fgetc() with invalid arguments --\n";
23$invalid_args = array (
24  "string",
25  10,
26  10.5,
27  true,
28  array(1,2,3),
29  new stdclass,
30);
31/* loop to test fgetc() with different invalid type of args */
32for($loop_counter = 1; $loop_counter <= count($invalid_args); $loop_counter++) {
33  echo "-- Iteration $loop_counter --\n";
34  var_dump( fgetc($invalid_args[$loop_counter - 1]) );
35}
36
37echo "Done\n";
38--EXPECTF--
39*** Testing error conditions ***
40-- Testing fgetc() with zero argument --
41
42Warning: fgetc() expects exactly 1 parameter, 0 given in %s on line %d
43bool(false)
44-- Testing fgetc() with more than expected number of arguments --
45
46Warning: fgetc() expects exactly 1 parameter, 2 given in %s on line %d
47bool(false)
48-- Testing fgetc() with invalid arguments --
49-- Iteration 1 --
50
51Warning: fgetc() expects parameter 1 to be resource, string given in %s on line %d
52bool(false)
53-- Iteration 2 --
54
55Warning: fgetc() expects parameter 1 to be resource, integer given in %s on line %d
56bool(false)
57-- Iteration 3 --
58
59Warning: fgetc() expects parameter 1 to be resource, float given in %s on line %d
60bool(false)
61-- Iteration 4 --
62
63Warning: fgetc() expects parameter 1 to be resource, boolean given in %s on line %d
64bool(false)
65-- Iteration 5 --
66
67Warning: fgetc() expects parameter 1 to be resource, array given in %s on line %d
68bool(false)
69-- Iteration 6 --
70
71Warning: fgetc() expects parameter 1 to be resource, object given in %s on line %d
72bool(false)
73Done
74