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 values 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 argument 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 elseif (is_array($v)) { 79 asort($v); 80 var_dump($v); 81 } else { 82 var_dump($v); 83 } 84 85 $v = get_html_translation_table($table, $quote_style, "UTF-8"); 86 if (is_array($v) && count($v) > 100) 87 var_dump(count($v)); 88 elseif (is_array($v)) { 89 asort($v); 90 var_dump($v); 91 } else { 92 var_dump($v); 93 } 94 95 $counter ++; 96} 97 98// close resource 99fclose($fp); 100 101echo "Done\n"; 102?> 103--EXPECTF-- 104*** Testing get_html_translation_table() : usage variations *** 105 106--- Testing get_html_translation_table() by supplying different values for 'table' argument --- 107-- Iteration 1 -- 108 109Warning: get_html_translation_table() expects parameter 1 to be int, array given in %s on line %d 110NULL 111 112Warning: get_html_translation_table() expects parameter 1 to be int, array given in %s on line %d 113NULL 114-- Iteration 2 -- 115 116Warning: get_html_translation_table() expects parameter 1 to be int, array given in %s on line %d 117NULL 118 119Warning: get_html_translation_table() expects parameter 1 to be int, array given in %s on line %d 120NULL 121-- Iteration 3 -- 122 123Warning: get_html_translation_table() expects parameter 1 to be int, array given in %s on line %d 124NULL 125 126Warning: get_html_translation_table() expects parameter 1 to be int, array given in %s on line %d 127NULL 128-- Iteration 4 -- 129 130Warning: get_html_translation_table() expects parameter 1 to be int, array given in %s on line %d 131NULL 132 133Warning: get_html_translation_table() expects parameter 1 to be int, array given in %s on line %d 134NULL 135-- Iteration 5 -- 136 137Warning: get_html_translation_table() expects parameter 1 to be int, array given in %s on line %d 138NULL 139 140Warning: get_html_translation_table() expects parameter 1 to be int, array given in %s on line %d 141NULL 142-- Iteration 6 -- 143int(252) 144int(252) 145-- Iteration 7 -- 146array(4) { 147 ["&"]=> 148 string(5) "&" 149 [">"]=> 150 string(4) ">" 151 ["<"]=> 152 string(4) "<" 153 ["""]=> 154 string(6) """ 155} 156array(4) { 157 ["&"]=> 158 string(5) "&" 159 [">"]=> 160 string(4) ">" 161 ["<"]=> 162 string(4) "<" 163 ["""]=> 164 string(6) """ 165} 166-- Iteration 8 -- 167int(252) 168int(252) 169-- Iteration 9 -- 170array(4) { 171 ["&"]=> 172 string(5) "&" 173 [">"]=> 174 string(4) ">" 175 ["<"]=> 176 string(4) "<" 177 ["""]=> 178 string(6) """ 179} 180array(4) { 181 ["&"]=> 182 string(5) "&" 183 [">"]=> 184 string(4) ">" 185 ["<"]=> 186 string(4) "<" 187 ["""]=> 188 string(6) """ 189} 190-- Iteration 10 -- 191 192Warning: get_html_translation_table() expects parameter 1 to be int, string given in %s on line %d 193NULL 194 195Warning: get_html_translation_table() expects parameter 1 to be int, string given in %s on line %d 196NULL 197-- Iteration 11 -- 198 199Warning: get_html_translation_table() expects parameter 1 to be int, string given in %s on line %d 200NULL 201 202Warning: get_html_translation_table() expects parameter 1 to be int, string given in %s on line %d 203NULL 204-- Iteration 12 -- 205 206Warning: get_html_translation_table() expects parameter 1 to be int, object given in %s on line %d 207NULL 208 209Warning: get_html_translation_table() expects parameter 1 to be int, object given in %s on line %d 210NULL 211-- Iteration 13 -- 212 213Warning: get_html_translation_table() expects parameter 1 to be int, string given in %s on line %d 214NULL 215 216Warning: get_html_translation_table() expects parameter 1 to be int, string given in %s on line %d 217NULL 218-- Iteration 14 -- 219 220Warning: get_html_translation_table() expects parameter 1 to be int, string given in %s on line %d 221NULL 222 223Warning: get_html_translation_table() expects parameter 1 to be int, string given in %s on line %d 224NULL 225-- Iteration 15 -- 226array(4) { 227 ["&"]=> 228 string(5) "&" 229 [">"]=> 230 string(4) ">" 231 ["<"]=> 232 string(4) "<" 233 ["""]=> 234 string(6) """ 235} 236array(4) { 237 ["&"]=> 238 string(5) "&" 239 [">"]=> 240 string(4) ">" 241 ["<"]=> 242 string(4) "<" 243 ["""]=> 244 string(6) """ 245} 246-- Iteration 16 -- 247array(4) { 248 ["&"]=> 249 string(5) "&" 250 [">"]=> 251 string(4) ">" 252 ["<"]=> 253 string(4) "<" 254 ["""]=> 255 string(6) """ 256} 257array(4) { 258 ["&"]=> 259 string(5) "&" 260 [">"]=> 261 string(4) ">" 262 ["<"]=> 263 string(4) "<" 264 ["""]=> 265 string(6) """ 266} 267-- Iteration 17 -- 268 269Warning: get_html_translation_table() expects parameter 1 to be int, resource given in %s on line %d 270NULL 271 272Warning: get_html_translation_table() expects parameter 1 to be int, resource given in %s on line %d 273NULL 274-- Iteration 18 -- 275array(4) { 276 ["&"]=> 277 string(5) "&" 278 [">"]=> 279 string(4) ">" 280 ["<"]=> 281 string(4) "<" 282 ["""]=> 283 string(6) """ 284} 285array(4) { 286 ["&"]=> 287 string(5) "&" 288 [">"]=> 289 string(4) ">" 290 ["<"]=> 291 string(4) "<" 292 ["""]=> 293 string(6) """ 294} 295-- Iteration 19 -- 296array(4) { 297 ["&"]=> 298 string(5) "&" 299 [">"]=> 300 string(4) ">" 301 ["<"]=> 302 string(4) "<" 303 ["""]=> 304 string(6) """ 305} 306array(4) { 307 ["&"]=> 308 string(5) "&" 309 [">"]=> 310 string(4) ">" 311 ["<"]=> 312 string(4) "<" 313 ["""]=> 314 string(6) """ 315} 316Done 317