1--TEST-- 2Test htmlspecialchars_decode() function : usage variations - unexpected values for 'string' argument 3--FILE-- 4<?php 5/* Prototype : string htmlspecialchars_decode(string $string [, int $quote_style]) 6 * Description: Convert special HTML entities back to characters 7 * Source code: ext/standard/html.c 8*/ 9 10/* 11 * testing htmlspecialchars_decode() with unexpected input values for $string argument 12*/ 13 14echo "*** Testing htmlspecialchars_decode() : usage variations ***\n"; 15 16//get a class 17class classA 18{ 19 function __toString() { 20 return "ClassAObject"; 21 } 22} 23 24//get a resource variable 25$file_handle=fopen(__FILE__, "r"); 26 27//get an unset variable 28$unset_var = 10; 29unset($unset_var); 30 31//array of values to iterate over 32$values = array( 33 34 // int data 35 0, 36 1, 37 12345, 38 -2345, 39 40 // float data 41 10.5, 42 -10.5, 43 10.1234567e10, 44 10.7654321E-10, 45 .5, 46 47 // array data 48 array(), 49 array(0), 50 array(1), 51 array(1, 2), 52 array('color' => 'red', 'item' => 'pen'), 53 54 // null data 55 NULL, 56 null, 57 58 // boolean data 59 true, 60 false, 61 TRUE, 62 FALSE, 63 64 // empty data 65 "", 66 '', 67 68 // object data 69 new classA(), 70 71 // undefined data 72 @$undefined_var, 73 74 // unset data 75 @$unset_var, 76 77 //resource 78 $file_handle 79); 80 81// loop through each element of the array for string 82$iterator = 1; 83foreach($values as $value) { 84 echo "-- Iterator $iterator --\n"; 85 var_dump( htmlspecialchars_decode($value) ); 86 $iterator++; 87}; 88 89// close the file resource used 90fclose($file_handle); 91 92?> 93===DONE=== 94--EXPECTF-- 95*** Testing htmlspecialchars_decode() : usage variations *** 96-- Iterator 1 -- 97string(1) "0" 98-- Iterator 2 -- 99string(1) "1" 100-- Iterator 3 -- 101string(5) "12345" 102-- Iterator 4 -- 103string(5) "-2345" 104-- Iterator 5 -- 105string(4) "10.5" 106-- Iterator 6 -- 107string(5) "-10.5" 108-- Iterator 7 -- 109string(12) "101234567000" 110-- Iterator 8 -- 111string(13) "1.07654321E-9" 112-- Iterator 9 -- 113string(3) "0.5" 114-- Iterator 10 -- 115 116Warning: htmlspecialchars_decode() expects parameter 1 to be string, array given in %s on line %d 117NULL 118-- Iterator 11 -- 119 120Warning: htmlspecialchars_decode() expects parameter 1 to be string, array given in %s on line %d 121NULL 122-- Iterator 12 -- 123 124Warning: htmlspecialchars_decode() expects parameter 1 to be string, array given in %s on line %d 125NULL 126-- Iterator 13 -- 127 128Warning: htmlspecialchars_decode() expects parameter 1 to be string, array given in %s on line %d 129NULL 130-- Iterator 14 -- 131 132Warning: htmlspecialchars_decode() expects parameter 1 to be string, array given in %s on line %d 133NULL 134-- Iterator 15 -- 135string(0) "" 136-- Iterator 16 -- 137string(0) "" 138-- Iterator 17 -- 139string(1) "1" 140-- Iterator 18 -- 141string(0) "" 142-- Iterator 19 -- 143string(1) "1" 144-- Iterator 20 -- 145string(0) "" 146-- Iterator 21 -- 147string(0) "" 148-- Iterator 22 -- 149string(0) "" 150-- Iterator 23 -- 151string(12) "ClassAObject" 152-- Iterator 24 -- 153string(0) "" 154-- Iterator 25 -- 155string(0) "" 156-- Iterator 26 -- 157 158Warning: htmlspecialchars_decode() expects parameter 1 to be string, resource given in %s on line %d 159NULL 160===DONE=== 161 162