1--TEST--
2Test abs() function : usage variations - different data types as $number arg
3--FILE--
4<?php
5/*
6 * Pass different data types as $number argument to abs() to test behaviour
7 */
8
9echo "*** Testing abs() : usage variations ***\n";
10
11//get an unset variable
12$unset_var = 10;
13unset ($unset_var);
14
15// get a class
16class classA
17{
18  public function __toString() {
19    return "abs";
20  }
21}
22
23// heredoc string
24$heredoc = <<<EOT
25abs
26EOT;
27
28// get a resource variable
29$fp = fopen(__FILE__, "r");
30
31// unexpected values to be passed to $number argument
32$inputs = array(
33
34       // null data
35/*10*/ NULL,
36       null,
37
38       // boolean data
39/*12*/ true,
40       false,
41       TRUE,
42       FALSE,
43
44       // empty data
45/*16*/ "",
46       '',
47       array(),
48
49       // string data
50/*19*/ "abs",
51       'abs',
52       $heredoc,
53
54       // object data
55/*22*/ new classA(),
56
57       // undefined data
58/*23*/ @$undefined_var,
59
60       // unset data
61/*24*/ @$unset_var,
62
63       // resource variable
64/*25*/ $fp
65);
66
67// loop through each element of $inputs to check the behavior of abs()
68$iterator = 1;
69foreach($inputs as $input) {
70    echo "\n-- Iteration $iterator --\n";
71    try {
72        var_dump(abs($input));
73    } catch (TypeError $e) {
74        echo $e->getMessage(), "\n";
75    }
76    $iterator++;
77};
78
79fclose($fp);
80?>
81--EXPECTF--
82*** Testing abs() : usage variations ***
83
84-- Iteration 1 --
85
86Deprecated: abs(): Passing null to parameter #1 ($num) of type int|float is deprecated in %s on line %d
87int(0)
88
89-- Iteration 2 --
90
91Deprecated: abs(): Passing null to parameter #1 ($num) of type int|float is deprecated in %s on line %d
92int(0)
93
94-- Iteration 3 --
95int(1)
96
97-- Iteration 4 --
98int(0)
99
100-- Iteration 5 --
101int(1)
102
103-- Iteration 6 --
104int(0)
105
106-- Iteration 7 --
107abs(): Argument #1 ($num) must be of type int|float, string given
108
109-- Iteration 8 --
110abs(): Argument #1 ($num) must be of type int|float, string given
111
112-- Iteration 9 --
113abs(): Argument #1 ($num) must be of type int|float, array given
114
115-- Iteration 10 --
116abs(): Argument #1 ($num) must be of type int|float, string given
117
118-- Iteration 11 --
119abs(): Argument #1 ($num) must be of type int|float, string given
120
121-- Iteration 12 --
122abs(): Argument #1 ($num) must be of type int|float, string given
123
124-- Iteration 13 --
125abs(): Argument #1 ($num) must be of type int|float, classA given
126
127-- Iteration 14 --
128
129Deprecated: abs(): Passing null to parameter #1 ($num) of type int|float is deprecated in %s on line %d
130int(0)
131
132-- Iteration 15 --
133
134Deprecated: abs(): Passing null to parameter #1 ($num) of type int|float is deprecated in %s on line %d
135int(0)
136
137-- Iteration 16 --
138abs(): Argument #1 ($num) must be of type int|float, resource given
139