1--TEST--
2Test imagecolorallocate() function : usage variations  - passing different data types to fourth argument
3--SKIPIF--
4<?php
5if(!extension_loaded('gd')) {
6    die('skip gd extension is not loaded');
7}
8if(!function_exists('imagecreatetruecolor')) {
9    die('skip imagecreatetruecolor function is not available');
10}
11?>
12--FILE--
13<?php
14/* Prototype  : int imagecolorallocate(resource im, int red, int green, int blue)
15 * Description:  Allocate a color for an image
16 * Source code: ext/gd/gd.c
17 */
18echo "*** Testing imagecolorallocate() : usage variations ***\n";
19
20$im = imagecreatetruecolor(200, 200);
21$red = 10;
22$green = 10;
23
24$fp = tmpfile();
25
26//get an unset variable
27$unset_var = 10;
28unset ($unset_var);
29// define some classes
30class classWithToString
31{
32        public function __toString() {
33                return "Class A object";
34        }
35}
36
37
38class classWithoutToString
39{
40}
41
42// heredoc string
43$heredoc = <<<EOT
44hello world
45EOT;
46
47// add arrays
48$index_array = array (1, 2, 3);
49$assoc_array = array ('one' => 1, 'two' => 2);
50
51//array of values to iterate over
52$values = array(
53
54      // float data
55      'float 10.5' => 10.5,
56      'float -10.5' => -10.5,
57      'float 10.1234567e10' => 10.1234567e10,
58      'float 10.7654321E-10' => 10.7654321E-10,
59      'float .5' => .5,
60
61      // array data
62      'empty array' => array(),
63      'int indexed array' => $index_array,
64      'associative array' => $assoc_array,
65	  'nested arrays' => array('foo', $index_array, $assoc_array),
66
67      // null data
68	  'uppercase NULL' => NULL,
69      'lowercase null' => null,
70
71      // boolean data
72      'lowercase true' => true,
73      'lowercase false' =>false,
74      'uppercase TRUE' =>TRUE,
75      'uppercase FALSE' =>FALSE,
76
77      // empty data
78      'empty string DQ' => "",
79      'empty string SQ' => '',
80
81      // string data
82      'string DQ' => "string",
83      'string SQ' => 'string',
84      'mixed case string' => "sTrInG",
85      'heredoc' => $heredoc,
86
87      // object data
88      'instance of classWithToString' => new classWithToString(),
89      'instance of classWithoutToString' => new classWithoutToString(),
90
91      // undefined data
92      'undefined var' => @$undefined_var,
93
94      // unset data
95      'unset var' => @$unset_var,
96
97      //resource
98      "file resource" => $fp
99);
100// loop through each element of the array for red
101foreach($values as $key => $value) {
102      echo "\n--$key--\n";
103      var_dump( imagecolorallocate($im, $red, $green, $value) );
104};
105?>
106===DONE===
107--EXPECTF--
108*** Testing imagecolorallocate() : usage variations ***
109
110--float 10.5--
111int(657930)
112
113--float -10.5--
114int(657910)
115
116--float 10.1234567e10--
117bool(false)
118
119--float 10.7654321E-10--
120int(657920)
121
122--float .5--
123int(657920)
124
125--empty array--
126
127Warning: imagecolorallocate() expects parameter 4 to be long, array given in %s on line %d
128NULL
129
130--int indexed array--
131
132Warning: imagecolorallocate() expects parameter 4 to be long, array given in %s on line %d
133NULL
134
135--associative array--
136
137Warning: imagecolorallocate() expects parameter 4 to be long, array given in %s on line %d
138NULL
139
140--nested arrays--
141
142Warning: imagecolorallocate() expects parameter 4 to be long, array given in %s on line %d
143NULL
144
145--uppercase NULL--
146int(657920)
147
148--lowercase null--
149int(657920)
150
151--lowercase true--
152int(657921)
153
154--lowercase false--
155int(657920)
156
157--uppercase TRUE--
158int(657921)
159
160--uppercase FALSE--
161int(657920)
162
163--empty string DQ--
164
165Warning: imagecolorallocate() expects parameter 4 to be long, string given in %s on line %d
166NULL
167
168--empty string SQ--
169
170Warning: imagecolorallocate() expects parameter 4 to be long, string given in %s on line %d
171NULL
172
173--string DQ--
174
175Warning: imagecolorallocate() expects parameter 4 to be long, string given in %s on line %d
176NULL
177
178--string SQ--
179
180Warning: imagecolorallocate() expects parameter 4 to be long, string given in %s on line %d
181NULL
182
183--mixed case string--
184
185Warning: imagecolorallocate() expects parameter 4 to be long, string given in %s on line %d
186NULL
187
188--heredoc--
189
190Warning: imagecolorallocate() expects parameter 4 to be long, string given in %s on line %d
191NULL
192
193--instance of classWithToString--
194
195Warning: imagecolorallocate() expects parameter 4 to be long, object given in %s on line %d
196NULL
197
198--instance of classWithoutToString--
199
200Warning: imagecolorallocate() expects parameter 4 to be long, object given in %s on line %d
201NULL
202
203--undefined var--
204int(657920)
205
206--unset var--
207int(657920)
208
209--file resource--
210
211Warning: imagecolorallocate() expects parameter 4 to be long, resource given in %s on line %d
212NULL
213===DONE===