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