1--TEST-- 2Test utf8_decode() function : usage variations - different types for data 3--SKIPIF-- 4<?php 5if (!extension_loaded("xml")) { 6 print "skip - XML extension not loaded"; 7} 8?> 9--FILE-- 10<?php 11/* Prototype : proto string utf8_decode(string data) 12 * Description: Converts a UTF-8 encoded string to ISO-8859-1 13 * Source code: ext/xml/xml.c 14 * Alias to functions: 15 */ 16 17echo "*** Testing utf8_decode() : usage variations ***\n"; 18error_reporting(E_ALL & ~E_NOTICE); 19 20class aClass { 21 function __toString() { 22 return "Some Ascii Data"; 23 } 24} 25 26// Initialise function arguments not being substituted (if any) 27 28//get an unset variable 29$unset_var = 10; 30unset ($unset_var); 31 32//array of values to iterate over 33$values = array( 34 35 // int data 36 0, 37 1, 38 12345, 39 -2345, 40 41 // float data 42 10.5, 43 -10.5, 44 10.1234567e10, 45 10.7654321E-10, 46 .5, 47 48 // array data 49 array(), 50 array(0), 51 array(1), 52 array(1, 2), 53 array('color' => 'red', 'item' => 'pen'), 54 55 // null data 56 NULL, 57 null, 58 59 // boolean data 60 true, 61 false, 62 TRUE, 63 FALSE, 64 65 // empty data 66 "", 67 '', 68 69 // object data 70 new aClass(), 71 72 // undefined data 73 $undefined_var, 74 75 // unset data 76 $unset_var, 77); 78 79// loop through each element of the array for data 80 81foreach($values as $value) { 82 echo "\nArg value $value \n"; 83 var_dump( utf8_decode($value) ); 84}; 85 86echo "Done"; 87?> 88--EXPECTF-- 89*** Testing utf8_decode() : usage variations *** 90 91Arg value 0 92string(1) "0" 93 94Arg value 1 95string(1) "1" 96 97Arg value 12345 98string(5) "12345" 99 100Arg value -2345 101string(5) "-2345" 102 103Arg value 10.5 104string(4) "10.5" 105 106Arg value -10.5 107string(5) "-10.5" 108 109Arg value 101234567000 110string(12) "101234567000" 111 112Arg value 1.07654321E-9 113string(13) "1.07654321E-9" 114 115Arg value 0.5 116string(3) "0.5" 117 118Arg value Array 119 120Warning: utf8_decode() expects parameter 1 to be string, array given in %s on line %d 121NULL 122 123Arg value Array 124 125Warning: utf8_decode() expects parameter 1 to be string, array given in %s on line %d 126NULL 127 128Arg value Array 129 130Warning: utf8_decode() expects parameter 1 to be string, array given in %s on line %d 131NULL 132 133Arg value Array 134 135Warning: utf8_decode() expects parameter 1 to be string, array given in %s on line %d 136NULL 137 138Arg value Array 139 140Warning: utf8_decode() expects parameter 1 to be string, array given in %s on line %d 141NULL 142 143Arg value 144string(0) "" 145 146Arg value 147string(0) "" 148 149Arg value 1 150string(1) "1" 151 152Arg value 153string(0) "" 154 155Arg value 1 156string(1) "1" 157 158Arg value 159string(0) "" 160 161Arg value 162string(0) "" 163 164Arg value 165string(0) "" 166 167Arg value Some Ascii Data 168string(15) "Some Ascii Data" 169 170Arg value 171string(0) "" 172 173Arg value 174string(0) "" 175Done 176 177