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