1--TEST--
2Test rand() function : usage variations - different data types as $max argument
3--SKIPIF--
4<?php if (PHP_INT_SIZE !== 4) die("skip this test is for 32-bit only");
5--FILE--
6<?php
7/* Prototype  : int rand  ([ int $min  , int $max ] )
8 * Description: Generate a random integer.
9 * Source code: ext/standard/rand.c
10 */
11
12echo "*** Testing rand) : usage variations ***\n";
13
14//get an unset variable
15$unset_var = 10;
16unset ($unset_var);
17
18// heredoc string
19$heredoc = <<<EOT
20abc
21xyz
22EOT;
23
24// get a class
25class classA
26{
27}
28
29// get a resource variable
30$fp = fopen(__FILE__, "r");
31
32$inputs = array(
33       // int data
34/*1*/  0,
35       1,
36       12345,
37       -2345,
38       2147483647,
39
40       // float data
41/*6*/  10.5,
42       -10.5,
43       12.3456789000e10,
44       12.3456789000E-10,
45       .5,
46
47       // null data
48/*11*/ NULL,
49       null,
50
51       // boolean data
52/*13*/ true,
53       false,
54       TRUE,
55       FALSE,
56
57       // empty data
58/*17*/ "",
59       '',
60       array(),
61
62       // string data
63/*20*/ "abcxyz",
64       'abcxyz',
65       $heredoc,
66
67       // object data
68/*23*/ new classA(),
69
70       // undefined data
71/*24*/ @$undefined_var,
72
73       // unset data
74/*25*/ @$unset_var,
75
76       // resource variable
77/*26*/ $fp
78);
79
80// loop through each element of $inputs to check the behaviour of rand()
81$iterator = 1;
82foreach($inputs as $input) {
83	echo "\n-- Iteration $iterator --\n";
84	var_dump(rand(100, $input));
85	$iterator++;
86};
87fclose($fp);
88?>
89===Done===
90--EXPECTF--
91*** Testing rand) : usage variations ***
92
93-- Iteration 1 --
94int(%i)
95
96-- Iteration 2 --
97int(%i)
98
99-- Iteration 3 --
100int(%i)
101
102-- Iteration 4 --
103int(%i)
104
105-- Iteration 5 --
106int(%i)
107
108-- Iteration 6 --
109int(%i)
110
111-- Iteration 7 --
112int(%i)
113
114-- Iteration 8 --
115
116Warning: rand() expects parameter 2 to be integer, float given in %s on line %d
117NULL
118
119-- Iteration 9 --
120int(%i)
121
122-- Iteration 10 --
123int(%i)
124
125-- Iteration 11 --
126int(%i)
127
128-- Iteration 12 --
129int(%i)
130
131-- Iteration 13 --
132int(%i)
133
134-- Iteration 14 --
135int(%i)
136
137-- Iteration 15 --
138int(%i)
139
140-- Iteration 16 --
141int(%i)
142
143-- Iteration 17 --
144
145Warning: rand() expects parameter 2 to be integer, string given in %s on line %d
146NULL
147
148-- Iteration 18 --
149
150Warning: rand() expects parameter 2 to be integer, string given in %s on line %d
151NULL
152
153-- Iteration 19 --
154
155Warning: rand() expects parameter 2 to be integer, array given in %s on line %d
156NULL
157
158-- Iteration 20 --
159
160Warning: rand() expects parameter 2 to be integer, string given in %s on line %d
161NULL
162
163-- Iteration 21 --
164
165Warning: rand() expects parameter 2 to be integer, string given in %s on line %d
166NULL
167
168-- Iteration 22 --
169
170Warning: rand() expects parameter 2 to be integer, string given in %s on line %d
171NULL
172
173-- Iteration 23 --
174
175Warning: rand() expects parameter 2 to be integer, object given in %s on line %d
176NULL
177
178-- Iteration 24 --
179int(%i)
180
181-- Iteration 25 --
182int(%i)
183
184-- Iteration 26 --
185
186Warning: rand() expects parameter 2 to be integer, resource given in %s on line %d
187NULL
188===Done===
189