1--TEST-- 2Test strval() function 3--INI-- 4precision=14 5--FILE-- 6<?php 7/* Prototype: string strval ( mixed $var ); 8 * Description: Returns the string value of var 9 */ 10 11echo "*** Testing str_val() with scalar values***\n"; 12$heredoc_string = <<<EOD 13This is a multiline heredoc 14string. Numeric = 1232455. 15EOD; 16/* heredoc string with only numeric values */ 17$heredoc_numeric_string = <<<EOD 1812345 192345 20EOD; 21/* null heredoc string */ 22$heredoc_empty_string = <<<EOD 23EOD; 24/* heredoc string with NULL */ 25$heredoc_NULL_string = <<<EOD 26NULL 27EOD; 28 29// different valid scalar values 30$scalars = array( 31 /* integers */ 32 0, 33 1, 34 -1, 35 -2147483648, // max negative integer value 36 -2147483647, 37 2147483647, // max positive integer value 38 2147483640, 39 0x123B, // integer as hexadecimal 40 0x12ab, 41 0Xfff, 42 0XFA, 43 44 /* floats */ 45 -0x80000000, // max negative integer as hexadecimal 46 0x7fffffff, // max positive integer as hexadecimal 47 0x7FFFFFFF, // max positive integer as hexadecimal 48 0123, // integer as octal 49 01, // should be quivalent to octal 1 50 -020000000000, // max negative integer as octal 51 017777777777, // max positive integer as octal 52 -2147483649, // float value 53 2147483648, // float value 54 -0x80000001, // float value, beyond max negative int 55 0x800000001, // float value, beyond max positive int 56 020000000001, // float value, beyond max positive int 57 -020000000001, // float value, beyond max negative int 58 0.0, 59 -0.1, 60 10.0000000000000000005, 61 10.5e+5, 62 1e-5, 63 .5e+7, 64 .6e-19, 65 .05E+44, 66 .0034E-30, 67 68 /* booleans */ 69 true, 70 TRUE, 71 FALSE, 72 false, 73 74 /* strings */ 75 "", 76 '', 77 " ", 78 ' ', 79 '0', 80 "0", 81 "testing", 82 "0x564", 83 "0123", 84 "new\n", 85 'new\n', 86 "@#$$%^&&*()", 87 " ", 88 "null", 89 'null', 90 'true', 91 "true", 92 /*"\0123", 93 "\0x12FF",*/ 94 $heredoc_string, 95 $heredoc_numeric_string, 96 $heredoc_empty_string 97); 98/* loop to check that strval() recognizes different 99 scalar values and returns the string conversion of same */ 100$loop_counter = 1; 101foreach ($scalars as $scalar ) { 102 echo "-- Iteration $loop_counter --\n"; $loop_counter++; 103 var_dump( strval($scalar) ); 104} 105 106echo "\n*** Testing strval() with non_scalar values ***\n"; 107// get a resource type variable 108$fp = fopen(__FILE__, "r"); 109$dfp = opendir( dirname(__FILE__) ); 110 111// unset variable 112$unset_var = 10; 113unset ($unset_var); 114 115// non_scalar values, objects, arrays, resources and boolean 116class foo 117{ 118 function __toString() { 119 return "Object"; 120 } 121} 122 123$not_scalars = array ( 124 new foo, //object 125 $fp, // resource 126 $dfp, 127 array(), // arrays 128 array(NULL), 129 array(1,2,3,4), 130 array("string"), 131 NULL, // nulls 132 null, 133 @$unset_var, // unset variable 134 @$undefined_var 135); 136/* loop through the $not_scalars to see working of 137 strval() on objects, arrays, boolean and others */ 138$loop_counter = 1; 139foreach ($not_scalars as $value ) { 140 echo "-- Iteration $loop_counter --\n"; $loop_counter++; 141 var_dump( strval($value) ); 142} 143 144echo "\n*** Testing error conditions ***\n"; 145//Zero argument 146var_dump( strval() ); 147 148//arguments more than expected 149var_dump( strval( $scalars[0], $scalars[1]) ); 150 151echo "Done\n"; 152 153// close the resources used 154fclose($fp); 155closedir($dfp); 156 157?> 158--EXPECTF-- 159*** Testing str_val() with scalar values*** 160-- Iteration 1 -- 161string(1) "0" 162-- Iteration 2 -- 163string(1) "1" 164-- Iteration 3 -- 165string(2) "-1" 166-- Iteration 4 -- 167string(11) "-2147483648" 168-- Iteration 5 -- 169string(11) "-2147483647" 170-- Iteration 6 -- 171string(10) "2147483647" 172-- Iteration 7 -- 173string(10) "2147483640" 174-- Iteration 8 -- 175string(4) "4667" 176-- Iteration 9 -- 177string(4) "4779" 178-- Iteration 10 -- 179string(4) "4095" 180-- Iteration 11 -- 181string(3) "250" 182-- Iteration 12 -- 183string(11) "-2147483648" 184-- Iteration 13 -- 185string(10) "2147483647" 186-- Iteration 14 -- 187string(10) "2147483647" 188-- Iteration 15 -- 189string(2) "83" 190-- Iteration 16 -- 191string(1) "1" 192-- Iteration 17 -- 193string(11) "-2147483648" 194-- Iteration 18 -- 195string(10) "2147483647" 196-- Iteration 19 -- 197string(11) "-2147483649" 198-- Iteration 20 -- 199string(10) "2147483648" 200-- Iteration 21 -- 201string(11) "-2147483649" 202-- Iteration 22 -- 203string(11) "34359738369" 204-- Iteration 23 -- 205string(10) "2147483649" 206-- Iteration 24 -- 207string(11) "-2147483649" 208-- Iteration 25 -- 209string(1) "0" 210-- Iteration 26 -- 211string(4) "-0.1" 212-- Iteration 27 -- 213string(2) "10" 214-- Iteration 28 -- 215string(7) "1050000" 216-- Iteration 29 -- 217string(6) "1.0E-5" 218-- Iteration 30 -- 219string(7) "5000000" 220-- Iteration 31 -- 221string(7) "6.0E-20" 222-- Iteration 32 -- 223string(7) "5.0E+42" 224-- Iteration 33 -- 225string(7) "3.4E-33" 226-- Iteration 34 -- 227string(1) "1" 228-- Iteration 35 -- 229string(1) "1" 230-- Iteration 36 -- 231string(0) "" 232-- Iteration 37 -- 233string(0) "" 234-- Iteration 38 -- 235string(0) "" 236-- Iteration 39 -- 237string(0) "" 238-- Iteration 40 -- 239string(1) " " 240-- Iteration 41 -- 241string(1) " " 242-- Iteration 42 -- 243string(1) "0" 244-- Iteration 43 -- 245string(1) "0" 246-- Iteration 44 -- 247string(7) "testing" 248-- Iteration 45 -- 249string(5) "0x564" 250-- Iteration 46 -- 251string(4) "0123" 252-- Iteration 47 -- 253string(4) "new 254" 255-- Iteration 48 -- 256string(5) "new\n" 257-- Iteration 49 -- 258string(11) "@#$$%^&&*()" 259-- Iteration 50 -- 260string(8) " " 261-- Iteration 51 -- 262string(4) "null" 263-- Iteration 52 -- 264string(4) "null" 265-- Iteration 53 -- 266string(4) "true" 267-- Iteration 54 -- 268string(4) "true" 269-- Iteration 55 -- 270string(5%d) "This is a multiline heredoc 271string. Numeric = 1232455." 272-- Iteration 56 -- 273string(1%d) "12345 2742345" 275-- Iteration 57 -- 276string(0) "" 277 278*** Testing strval() with non_scalar values *** 279-- Iteration 1 -- 280string(6) "Object" 281-- Iteration 2 -- 282string(14) "Resource id #%d" 283-- Iteration 3 -- 284string(14) "Resource id #%d" 285-- Iteration 4 -- 286 287Notice: Array to string conversion in %sstrval.php on line %d 288string(5) "Array" 289-- Iteration 5 -- 290 291Notice: Array to string conversion in %sstrval.php on line %d 292string(5) "Array" 293-- Iteration 6 -- 294 295Notice: Array to string conversion in %sstrval.php on line %d 296string(5) "Array" 297-- Iteration 7 -- 298 299Notice: Array to string conversion in %sstrval.php on line %d 300string(5) "Array" 301-- Iteration 8 -- 302string(0) "" 303-- Iteration 9 -- 304string(0) "" 305-- Iteration 10 -- 306string(0) "" 307-- Iteration 11 -- 308string(0) "" 309 310*** Testing error conditions *** 311 312Warning: strval() expects exactly 1 parameter, 0 given in %s on line %d 313NULL 314 315Warning: strval() expects exactly 1 parameter, 2 given in %s on line %d 316NULL 317Done 318