1--TEST-- 2Test get_html_translation_table() function : usage variations - unexpected table values 3--FILE-- 4<?php 5/* Prototype : array get_html_translation_table ( [int $table [, int $quote_style [, string charset_hint]]] ) 6 * Description: Returns the internal translation table used by htmlspecialchars and htmlentities 7 * Source code: ext/standard/html.c 8*/ 9 10/* 11 * test get_html_translation_table() with unexpected value for argument $table 12*/ 13 14echo "*** Testing get_html_translation_table() : usage variations ***\n"; 15// initialize all required variables 16$quote_style = ENT_COMPAT; 17 18// get an unset variable 19$unset_var = 10; 20unset($unset_var); 21 22// a resource variable 23$fp = fopen(__FILE__, "r"); 24 25// array with different values 26$values = array ( 27 28 // array values 29 array(), 30 array(0), 31 array(1), 32 array(1, 2), 33 array('color' => 'red', 'item' => 'pen'), 34 35 // boolean values 36 true, 37 false, 38 TRUE, 39 FALSE, 40 41 // string values 42 "string", 43 'string', 44 45 // objects 46 new stdclass(), 47 48 // empty string 49 "", 50 '', 51 52 // null vlaues 53 NULL, 54 null, 55 56 // resource var 57 $fp, 58 59 // undefined variable 60 @$undefined_var, 61 62 // unset variable 63 @$unset_var 64); 65 66 67// loop through each element of the array and check the working of get_html_translation_table() 68// when $table arugment is supplied with different values 69echo "\n--- Testing get_html_translation_table() by supplying different values for 'table' argument ---\n"; 70$counter = 1; 71for($index = 0; $index < count($values); $index ++) { 72 echo "-- Iteration $counter --\n"; 73 $table = $values [$index]; 74 75 $v = get_html_translation_table($table, ENT_COMPAT, "UTF-8"); 76 if (is_array($v) && count($v) > 100) 77 var_dump(count($v)); 78 else 79 var_dump($v); 80 81 $v = get_html_translation_table($table, $quote_style, "UTF-8"); 82 if (is_array($v) && count($v) > 100) 83 var_dump(count($v)); 84 else 85 var_dump($v); 86 87 $counter ++; 88} 89 90// close resource 91fclose($fp); 92 93echo "Done\n"; 94?> 95--EXPECTF-- 96*** Testing get_html_translation_table() : usage variations *** 97 98--- Testing get_html_translation_table() by supplying different values for 'table' argument --- 99-- Iteration 1 -- 100 101Warning: get_html_translation_table() expects parameter 1 to be long, array given in %s on line %d 102NULL 103 104Warning: get_html_translation_table() expects parameter 1 to be long, array given in %s on line %d 105NULL 106-- Iteration 2 -- 107 108Warning: get_html_translation_table() expects parameter 1 to be long, array given in %s on line %d 109NULL 110 111Warning: get_html_translation_table() expects parameter 1 to be long, array given in %s on line %d 112NULL 113-- Iteration 3 -- 114 115Warning: get_html_translation_table() expects parameter 1 to be long, array given in %s on line %d 116NULL 117 118Warning: get_html_translation_table() expects parameter 1 to be long, array given in %s on line %d 119NULL 120-- Iteration 4 -- 121 122Warning: get_html_translation_table() expects parameter 1 to be long, array given in %s on line %d 123NULL 124 125Warning: get_html_translation_table() expects parameter 1 to be long, array given in %s on line %d 126NULL 127-- Iteration 5 -- 128 129Warning: get_html_translation_table() expects parameter 1 to be long, array given in %s on line %d 130NULL 131 132Warning: get_html_translation_table() expects parameter 1 to be long, array given in %s on line %d 133NULL 134-- Iteration 6 -- 135int(252) 136int(252) 137-- Iteration 7 -- 138array(4) { 139 ["&"]=> 140 string(5) "&" 141 ["""]=> 142 string(6) """ 143 ["<"]=> 144 string(4) "<" 145 [">"]=> 146 string(4) ">" 147} 148array(4) { 149 ["&"]=> 150 string(5) "&" 151 ["""]=> 152 string(6) """ 153 ["<"]=> 154 string(4) "<" 155 [">"]=> 156 string(4) ">" 157} 158-- Iteration 8 -- 159int(252) 160int(252) 161-- Iteration 9 -- 162array(4) { 163 ["&"]=> 164 string(5) "&" 165 ["""]=> 166 string(6) """ 167 ["<"]=> 168 string(4) "<" 169 [">"]=> 170 string(4) ">" 171} 172array(4) { 173 ["&"]=> 174 string(5) "&" 175 ["""]=> 176 string(6) """ 177 ["<"]=> 178 string(4) "<" 179 [">"]=> 180 string(4) ">" 181} 182-- Iteration 10 -- 183 184Warning: get_html_translation_table() expects parameter 1 to be long, string given in %s on line %d 185NULL 186 187Warning: get_html_translation_table() expects parameter 1 to be long, string given in %s on line %d 188NULL 189-- Iteration 11 -- 190 191Warning: get_html_translation_table() expects parameter 1 to be long, string given in %s on line %d 192NULL 193 194Warning: get_html_translation_table() expects parameter 1 to be long, string given in %s on line %d 195NULL 196-- Iteration 12 -- 197 198Warning: get_html_translation_table() expects parameter 1 to be long, object given in %s on line %d 199NULL 200 201Warning: get_html_translation_table() expects parameter 1 to be long, object given in %s on line %d 202NULL 203-- Iteration 13 -- 204 205Warning: get_html_translation_table() expects parameter 1 to be long, string given in %s on line %d 206NULL 207 208Warning: get_html_translation_table() expects parameter 1 to be long, string given in %s on line %d 209NULL 210-- Iteration 14 -- 211 212Warning: get_html_translation_table() expects parameter 1 to be long, string given in %s on line %d 213NULL 214 215Warning: get_html_translation_table() expects parameter 1 to be long, string given in %s on line %d 216NULL 217-- Iteration 15 -- 218array(4) { 219 ["&"]=> 220 string(5) "&" 221 ["""]=> 222 string(6) """ 223 ["<"]=> 224 string(4) "<" 225 [">"]=> 226 string(4) ">" 227} 228array(4) { 229 ["&"]=> 230 string(5) "&" 231 ["""]=> 232 string(6) """ 233 ["<"]=> 234 string(4) "<" 235 [">"]=> 236 string(4) ">" 237} 238-- Iteration 16 -- 239array(4) { 240 ["&"]=> 241 string(5) "&" 242 ["""]=> 243 string(6) """ 244 ["<"]=> 245 string(4) "<" 246 [">"]=> 247 string(4) ">" 248} 249array(4) { 250 ["&"]=> 251 string(5) "&" 252 ["""]=> 253 string(6) """ 254 ["<"]=> 255 string(4) "<" 256 [">"]=> 257 string(4) ">" 258} 259-- Iteration 17 -- 260 261Warning: get_html_translation_table() expects parameter 1 to be long, resource given in %s on line %d 262NULL 263 264Warning: get_html_translation_table() expects parameter 1 to be long, resource given in %s on line %d 265NULL 266-- Iteration 18 -- 267array(4) { 268 ["&"]=> 269 string(5) "&" 270 ["""]=> 271 string(6) """ 272 ["<"]=> 273 string(4) "<" 274 [">"]=> 275 string(4) ">" 276} 277array(4) { 278 ["&"]=> 279 string(5) "&" 280 ["""]=> 281 string(6) """ 282 ["<"]=> 283 string(4) "<" 284 [">"]=> 285 string(4) ">" 286} 287-- Iteration 19 -- 288array(4) { 289 ["&"]=> 290 string(5) "&" 291 ["""]=> 292 string(6) """ 293 ["<"]=> 294 string(4) "<" 295 [">"]=> 296 string(4) ">" 297} 298array(4) { 299 ["&"]=> 300 string(5) "&" 301 ["""]=> 302 string(6) """ 303 ["<"]=> 304 string(4) "<" 305 [">"]=> 306 string(4) ">" 307} 308Done 309