Return to strval.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / general_functions |
1.1 misho 1: --TEST-- 2: Test strval() function 3: --INI-- 4: precision=14 5: --FILE-- 6: <?php 7: /* Prototype: string strval ( mixed $var ); 8: * Description: Returns the string value of var 9: */ 10: 11: echo "*** Testing str_val() with scalar values***\n"; 12: $heredoc_string = <<<EOD 13: This is a multiline heredoc 14: string. Numeric = 1232455. 15: EOD; 16: /* heredoc string with only numeric values */ 17: $heredoc_numeric_string = <<<EOD 18: 12345 19: 2345 20: EOD; 21: /* null heredoc string */ 22: $heredoc_empty_string = <<<EOD 23: EOD; 24: /* heredoc string with NULL */ 25: $heredoc_NULL_string = <<<EOD 26: NULL 27: EOD; 28: 29: // different valid scalar vlaues 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 postive integer as hexadecimal 47: 0x7FFFFFFF, // max postive integer as hexadecimal 48: 0123, // integer as octal 49: 01912, // 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 retuns the string conversion of same */ 100: $loop_counter = 1; 101: foreach ($scalars as $scalar ) { 102: echo "-- Iteration $loop_counter --\n"; $loop_counter++; 103: var_dump( strval($scalar) ); 104: } 105: 106: echo "\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; 113: unset ($unset_var); 114: 115: // non_scalar values, objects, arrays, resources and boolean 116: class 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; 139: foreach ($not_scalars as $value ) { 140: echo "-- Iteration $loop_counter --\n"; $loop_counter++; 141: var_dump( strval($value) ); 142: } 143: 144: echo "\n*** Testing error conditions ***\n"; 145: //Zero argument 146: var_dump( strval() ); 147: 148: //arguments more than expected 149: var_dump( strval( $scalars[0], $scalars[1]) ); 150: 151: echo "Done\n"; 152: 153: // close the resources used 154: fclose($fp); 155: closedir($dfp); 156: 157: ?> 158: --EXPECTF-- 159: *** Testing str_val() with scalar values*** 160: -- Iteration 1 -- 161: string(1) "0" 162: -- Iteration 2 -- 163: string(1) "1" 164: -- Iteration 3 -- 165: string(2) "-1" 166: -- Iteration 4 -- 167: string(11) "-2147483648" 168: -- Iteration 5 -- 169: string(11) "-2147483647" 170: -- Iteration 6 -- 171: string(10) "2147483647" 172: -- Iteration 7 -- 173: string(10) "2147483640" 174: -- Iteration 8 -- 175: string(4) "4667" 176: -- Iteration 9 -- 177: string(4) "4779" 178: -- Iteration 10 -- 179: string(4) "4095" 180: -- Iteration 11 -- 181: string(3) "250" 182: -- Iteration 12 -- 183: string(11) "-2147483648" 184: -- Iteration 13 -- 185: string(10) "2147483647" 186: -- Iteration 14 -- 187: string(10) "2147483647" 188: -- Iteration 15 -- 189: string(2) "83" 190: -- Iteration 16 -- 191: string(1) "1" 192: -- Iteration 17 -- 193: string(11) "-2147483648" 194: -- Iteration 18 -- 195: string(10) "2147483647" 196: -- Iteration 19 -- 197: string(11) "-2147483649" 198: -- Iteration 20 -- 199: string(10) "2147483648" 200: -- Iteration 21 -- 201: string(11) "-2147483649" 202: -- Iteration 22 -- 203: string(11) "34359738369" 204: -- Iteration 23 -- 205: string(10) "2147483649" 206: -- Iteration 24 -- 207: string(11) "-2147483649" 208: -- Iteration 25 -- 209: string(1) "0" 210: -- Iteration 26 -- 211: string(4) "-0.1" 212: -- Iteration 27 -- 213: string(2) "10" 214: -- Iteration 28 -- 215: string(7) "1050000" 216: -- Iteration 29 -- 217: string(6) "1.0E-5" 218: -- Iteration 30 -- 219: string(7) "5000000" 220: -- Iteration 31 -- 221: string(7) "6.0E-20" 222: -- Iteration 32 -- 223: string(7) "5.0E+42" 224: -- Iteration 33 -- 225: string(7) "3.4E-33" 226: -- Iteration 34 -- 227: string(1) "1" 228: -- Iteration 35 -- 229: string(1) "1" 230: -- Iteration 36 -- 231: string(0) "" 232: -- Iteration 37 -- 233: string(0) "" 234: -- Iteration 38 -- 235: string(0) "" 236: -- Iteration 39 -- 237: string(0) "" 238: -- Iteration 40 -- 239: string(1) " " 240: -- Iteration 41 -- 241: string(1) " " 242: -- Iteration 42 -- 243: string(1) "0" 244: -- Iteration 43 -- 245: string(1) "0" 246: -- Iteration 44 -- 247: string(7) "testing" 248: -- Iteration 45 -- 249: string(5) "0x564" 250: -- Iteration 46 -- 251: string(4) "0123" 252: -- Iteration 47 -- 253: string(4) "new 254: " 255: -- Iteration 48 -- 256: string(5) "new\n" 257: -- Iteration 49 -- 258: string(11) "@#$$%^&&*()" 259: -- Iteration 50 -- 260: string(8) " " 261: -- Iteration 51 -- 262: string(4) "null" 263: -- Iteration 52 -- 264: string(4) "null" 265: -- Iteration 53 -- 266: string(4) "true" 267: -- Iteration 54 -- 268: string(4) "true" 269: -- Iteration 55 -- 270: string(5%d) "This is a multiline heredoc 271: string. Numeric = 1232455." 272: -- Iteration 56 -- 273: string(1%d) "12345 274: 2345" 275: -- Iteration 57 -- 276: string(0) "" 277: 278: *** Testing strval() with non_scalar values *** 279: -- Iteration 1 -- 280: string(6) "Object" 281: -- Iteration 2 -- 282: string(14) "Resource id #5" 283: -- Iteration 3 -- 284: string(14) "Resource id #6" 285: -- Iteration 4 -- 286: string(5) "Array" 287: -- Iteration 5 -- 288: string(5) "Array" 289: -- Iteration 6 -- 290: string(5) "Array" 291: -- Iteration 7 -- 292: string(5) "Array" 293: -- Iteration 8 -- 294: string(0) "" 295: -- Iteration 9 -- 296: string(0) "" 297: -- Iteration 10 -- 298: string(0) "" 299: -- Iteration 11 -- 300: string(0) "" 301: 302: *** Testing error conditions *** 303: 304: Warning: strval() expects exactly 1 parameter, 0 given in %s on line %d 305: NULL 306: 307: Warning: strval() expects exactly 1 parameter, 2 given in %s on line %d 308: NULL 309: Done