1--TEST-- 2Test money_format() function : usage variations - test values for $number argument 3--SKIPIF-- 4<?php 5 if (!function_exists('money_format')) { 6 die("SKIP money_format - not supported\n"); 7 } 8?> 9--FILE-- 10<?php 11/* Prototype : string money_format ( string $format , float $number ) 12 * Description: Formats a number as a currency string 13 * Source code: ext/standard/string.c 14*/ 15 16// =========================================================================================== 17// = We do not test for exact return-values, as those might be different between OS-versions = 18// =========================================================================================== 19 20echo "*** Testing money_format() function: with unexpected inputs for 'number' argument ***\n"; 21 22//get an unset variable 23$unset_var = ' string_val '; 24unset($unset_var); 25 26//defining a couple of sample classes 27class class_no_tostring { 28} 29 30class class_with_tostring { 31 public function __toString() { 32 return " sample object "; 33 } 34} 35 36 37//getting the resource 38$file_handle = fopen(__FILE__, "r"); 39 40// array with different values for $number 41$numbers = array ( 42 43 // integer values 44/*1*/ 0, 45 1, 46 255, 47 256, 48 2147483647, 49 -2147483648, 50 51 // float values 52/*7*/ 10.5, 53 -20.5, 54 10.1234567e10, 55 56 // array values 57/*10*/ array(), 58 array(0), 59 array(1, 2), 60 61 // boolean values 62/*13*/ true, 63 false, 64 TRUE, 65 FALSE, 66 67 // null values 68/*17*/ NULL, 69 null, 70 71 // string values 72/*19*/ "abcd", 73 'abcd', 74 "0x12f", 75 "%=*!14#8.2nabcd", 76 77 // objects 78/*23*/ new class_no_tostring(), 79 new class_with_tostring(), 80 81 // resource 82/*25*/ $file_handle, 83 84 // undefined variable 85/*26*/ @$undefined_var, 86 87 // unset variable 88/*27*/ @$unset_var 89); 90 91// loop through with each element of the $numbers array to test money_format() function 92$count = 1; 93$format = '%14#8.2i'; 94 95foreach($numbers as $number) { 96 echo "-- Iteration $count --\n"; 97 echo gettype(money_format($format, $number))."\n"; 98 $count ++; 99} 100 101// close the file handle 102fclose($file_handle); 103 104?> 105===Done=== 106--EXPECTF-- 107*** Testing money_format() function: with unexpected inputs for 'number' argument *** 108-- Iteration 1 -- 109string 110-- Iteration 2 -- 111string 112-- Iteration 3 -- 113string 114-- Iteration 4 -- 115string 116-- Iteration 5 -- 117string 118-- Iteration 6 -- 119string 120-- Iteration 7 -- 121string 122-- Iteration 8 -- 123string 124-- Iteration 9 -- 125string 126-- Iteration 10 -- 127 128Warning: money_format() expects parameter 2 to be float, array given in %s on line %d 129NULL 130-- Iteration 11 -- 131 132Warning: money_format() expects parameter 2 to be float, array given in %s on line %d 133NULL 134-- Iteration 12 -- 135 136Warning: money_format() expects parameter 2 to be float, array given in %s on line %d 137NULL 138-- Iteration 13 -- 139string 140-- Iteration 14 -- 141string 142-- Iteration 15 -- 143string 144-- Iteration 16 -- 145string 146-- Iteration 17 -- 147string 148-- Iteration 18 -- 149string 150-- Iteration 19 -- 151 152Warning: money_format() expects parameter 2 to be float, string given in %s on line %d 153NULL 154-- Iteration 20 -- 155 156Warning: money_format() expects parameter 2 to be float, string given in %s on line %d 157NULL 158-- Iteration 21 -- 159 160Notice: A non well formed numeric value encountered in %s on line %d 161string 162-- Iteration 22 -- 163 164Warning: money_format() expects parameter 2 to be float, string given in %s on line %d 165NULL 166-- Iteration 23 -- 167 168Warning: money_format() expects parameter 2 to be float, object given in %s on line %d 169NULL 170-- Iteration 24 -- 171 172Warning: money_format() expects parameter 2 to be float, object given in %s on line %d 173NULL 174-- Iteration 25 -- 175 176Warning: money_format() expects parameter 2 to be float, resource given in %s on line %d 177NULL 178-- Iteration 26 -- 179string 180-- Iteration 27 -- 181string 182===Done=== 183