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