Annotation of embedaddon/php/ext/standard/tests/strings/vsprintf_variation2.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test vsprintf() function : usage variations - unexpected values for args argument
! 3: --FILE--
! 4: <?php
! 5: /* Prototype : string vsprintf(string format, array args)
! 6: * Description: Return a formatted string
! 7: * Source code: ext/standard/formatted_print.c
! 8: */
! 9:
! 10: /*
! 11: * Test vsprintf() when different unexpected values are passed to
! 12: * the '$args' arguments of the function
! 13: */
! 14:
! 15: echo "*** Testing vsprintf() : with unexpected values for args argument ***\n";
! 16:
! 17: // initialising the required variables
! 18: $format = '%s';
! 19:
! 20: //get an unset variable
! 21: $unset_var = 10;
! 22: unset ($unset_var);
! 23:
! 24: // declaring a class
! 25: class sample
! 26: {
! 27: public function __toString() {
! 28: return "object";
! 29: }
! 30: }
! 31:
! 32: // Defining resource
! 33: $file_handle = fopen(__FILE__, 'r');
! 34:
! 35:
! 36: //array of values to iterate over
! 37: $values = array(
! 38:
! 39: // int data
! 40: 0,
! 41: 1,
! 42: 12345,
! 43: -2345,
! 44:
! 45: // float data
! 46: 10.5,
! 47: -10.5,
! 48: 10.1234567e10,
! 49: 10.7654321E-10,
! 50: .5,
! 51:
! 52: // null data
! 53: NULL,
! 54: null,
! 55:
! 56: // boolean data
! 57: true,
! 58: false,
! 59: TRUE,
! 60: FALSE,
! 61:
! 62: // empty data
! 63: "",
! 64: '',
! 65:
! 66: // string data
! 67: "string",
! 68: 'string',
! 69:
! 70: // object data
! 71: new sample(),
! 72:
! 73: // undefined data
! 74: @$undefined_var,
! 75:
! 76: // unset data
! 77: @$unset_var,
! 78:
! 79: // resource data
! 80: $file_handle
! 81: );
! 82:
! 83: // loop through each element of the array for args
! 84: $counter = 1;
! 85: foreach($values as $value) {
! 86: echo "\n-- Iteration $counter --\n";
! 87: var_dump( vsprintf($format,$value) );
! 88: $counter++;
! 89: };
! 90:
! 91: // closing the resource
! 92: fclose($file_handle);
! 93:
! 94: echo "Done";
! 95: ?>
! 96: --EXPECTF--
! 97: *** Testing vsprintf() : with unexpected values for args argument ***
! 98:
! 99: -- Iteration 1 --
! 100: string(1) "0"
! 101:
! 102: -- Iteration 2 --
! 103: string(1) "1"
! 104:
! 105: -- Iteration 3 --
! 106: string(5) "12345"
! 107:
! 108: -- Iteration 4 --
! 109: string(5) "-2345"
! 110:
! 111: -- Iteration 5 --
! 112: string(4) "10.5"
! 113:
! 114: -- Iteration 6 --
! 115: string(5) "-10.5"
! 116:
! 117: -- Iteration 7 --
! 118: string(12) "101234567000"
! 119:
! 120: -- Iteration 8 --
! 121: string(13) "1.07654321E-9"
! 122:
! 123: -- Iteration 9 --
! 124: string(3) "0.5"
! 125:
! 126: -- Iteration 10 --
! 127:
! 128: Warning: vsprintf(): Too few arguments in %s on line %d
! 129: bool(false)
! 130:
! 131: -- Iteration 11 --
! 132:
! 133: Warning: vsprintf(): Too few arguments in %s on line %d
! 134: bool(false)
! 135:
! 136: -- Iteration 12 --
! 137: string(1) "1"
! 138:
! 139: -- Iteration 13 --
! 140: string(0) ""
! 141:
! 142: -- Iteration 14 --
! 143: string(1) "1"
! 144:
! 145: -- Iteration 15 --
! 146: string(0) ""
! 147:
! 148: -- Iteration 16 --
! 149: string(0) ""
! 150:
! 151: -- Iteration 17 --
! 152: string(0) ""
! 153:
! 154: -- Iteration 18 --
! 155: string(6) "string"
! 156:
! 157: -- Iteration 19 --
! 158: string(6) "string"
! 159:
! 160: -- Iteration 20 --
! 161:
! 162: Warning: vsprintf(): Too few arguments in %s on line %d
! 163: bool(false)
! 164:
! 165: -- Iteration 21 --
! 166:
! 167: Warning: vsprintf(): Too few arguments in %s on line %d
! 168: bool(false)
! 169:
! 170: -- Iteration 22 --
! 171:
! 172: Warning: vsprintf(): Too few arguments in %s on line %d
! 173: bool(false)
! 174:
! 175: -- Iteration 23 --
! 176: string(%d) "Resource id #%d"
! 177: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>