Annotation of embedaddon/php/ext/standard/tests/strings/vsprintf_variation1.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test vsprintf() function : usage variations - unexpected values for the format 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 format strings are passed to
12: * the '$format' argument of the function
13: */
14:
15: echo "*** Testing vsprintf() : with unexpected values for format argument ***\n";
16:
17: // initialising the required variables
18: $args = array(1, 2);
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: // array data
53: array(),
54: array(0),
55: array(1),
56: array(1,2),
57: array('color' => 'red', 'item' => 'pen'),
58:
59: // null data
60: NULL,
61: null,
62:
63: // boolean data
64: true,
65: false,
66: TRUE,
67: FALSE,
68:
69: // empty data
70: "",
71: '',
72:
73: // object data
74: new sample(),
75:
76: // undefined data
77: @$undefined_var,
78:
79: // unset data
80: @$unset_var,
81:
82: // resource data
83: $file_handle
84: );
85:
86: // loop through each element of the array for format
87:
88: $counter = 1;
89: foreach($values as $value) {
90: echo "\n -- Iteration $counter --\n";
91: var_dump( vsprintf($value,$args) );
92: $counter++;
93:
94: };
95:
96: // closing the resource
97: fclose($file_handle);
98:
99: echo "Done";
100: ?>
101: --EXPECTF--
102: *** Testing vsprintf() : with unexpected values for format argument ***
103:
104: -- Iteration 1 --
105: string(1) "0"
106:
107: -- Iteration 2 --
108: string(1) "1"
109:
110: -- Iteration 3 --
111: string(5) "12345"
112:
113: -- Iteration 4 --
114: string(5) "-2345"
115:
116: -- Iteration 5 --
117: string(4) "10.5"
118:
119: -- Iteration 6 --
120: string(5) "-10.5"
121:
122: -- Iteration 7 --
123: string(12) "101234567000"
124:
125: -- Iteration 8 --
126: string(13) "1.07654321E-9"
127:
128: -- Iteration 9 --
129: string(3) "0.5"
130:
131: -- Iteration 10 --
132:
133: Notice: Array to string conversion in %s on line %d
134: string(5) "Array"
135:
136: -- Iteration 11 --
137:
138: Notice: Array to string conversion in %s on line %d
139: string(5) "Array"
140:
141: -- Iteration 12 --
142:
143: Notice: Array to string conversion in %s on line %d
144: string(5) "Array"
145:
146: -- Iteration 13 --
147:
148: Notice: Array to string conversion in %s on line %d
149: string(5) "Array"
150:
151: -- Iteration 14 --
152:
153: Notice: Array to string conversion in %s on line %d
154: string(5) "Array"
155:
156: -- Iteration 15 --
157: string(0) ""
158:
159: -- Iteration 16 --
160: string(0) ""
161:
162: -- Iteration 17 --
163: string(1) "1"
164:
165: -- Iteration 18 --
166: string(0) ""
167:
168: -- Iteration 19 --
169: string(1) "1"
170:
171: -- Iteration 20 --
172: string(0) ""
173:
174: -- Iteration 21 --
175: string(0) ""
176:
177: -- Iteration 22 --
178: string(0) ""
179:
180: -- Iteration 23 --
181: string(6) "object"
182:
183: -- Iteration 24 --
184: string(0) ""
185:
186: -- Iteration 25 --
187: string(0) ""
188:
189: -- Iteration 26 --
190: string(%d) "Resource id #%d"
191: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>