Annotation of embedaddon/php/ext/standard/tests/strings/sprintf_variation1.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test sprintf() function : usage variations - unexpected values for format argument
3: --FILE--
4: <?php
5: /* Prototype : string sprintf(string $format [, mixed $arg1 [, mixed ...]])
6: * Description: Return a formatted string
7: * Source code: ext/standard/formatted_print.c
8: */
9:
10: /*
11: * Testing sprintf() : with different unexpected values for format argument other than the strings
12: */
13:
14: echo "*** Testing sprintf() : with unexpected values for format argument ***\n";
15:
16: // initialing required variables
17: $arg1 = "second arg";
18: $arg2 = "third arg";
19:
20: //get an unset variable
21: $unset_var = 10;
22: unset ($unset_var);
23:
24: // declaring class
25: class sample
26: {
27: public function __toString() {
28: return "Object";
29: }
30: }
31:
32: // creating a file resource
33: $file_handle = fopen(__FILE__, 'r');
34:
35: //array of values to iterate over
36: $values = array(
37:
38: // int data
39: 0,
40: 1,
41: 12345,
42: -2345,
43:
44: // float data
45: 10.5,
46: -10.5,
47: 10.1234567e10,
48: 10.7654321E-10,
49: .5,
50:
51: // array data
52: array(),
53: array(0),
54: array(1),
55: array(1, 2),
56: array('color' => 'red', 'item' => 'pen'),
57:
58: // null data
59: NULL,
60: null,
61:
62: // boolean data
63: true,
64: false,
65: TRUE,
66: FALSE,
67:
68: // empty data
69: "",
70: '',
71:
72: // object data
73: new sample(),
74:
75: // undefined data
76: @$undefined_var,
77:
78: // unset data
79: @$unset_var,
80:
81: // resource data
82: $file_handle
83: );
84:
85: // loop through each element of the array for format
86:
87: $count = 1;
88: foreach($values as $value) {
89: echo "\n-- Iteration $count --\n";
90:
91: // with default argument
92: var_dump( sprintf($value) );
93:
94: // with two arguments
95: var_dump( sprintf($value, $arg1) );
96:
97: // with three arguments
98: var_dump( sprintf($value, $arg1, $arg2) );
99:
100: $count++;
101: };
102:
103: // close the resource
104: fclose($file_handle);
105:
106: echo "Done";
107: ?>
108: --EXPECTF--
109: *** Testing sprintf() : with unexpected values for format argument ***
110:
111: -- Iteration 1 --
112: string(1) "0"
113: string(1) "0"
114: string(1) "0"
115:
116: -- Iteration 2 --
117: string(1) "1"
118: string(1) "1"
119: string(1) "1"
120:
121: -- Iteration 3 --
122: string(5) "12345"
123: string(5) "12345"
124: string(5) "12345"
125:
126: -- Iteration 4 --
127: string(5) "-2345"
128: string(5) "-2345"
129: string(5) "-2345"
130:
131: -- Iteration 5 --
132: string(4) "10.5"
133: string(4) "10.5"
134: string(4) "10.5"
135:
136: -- Iteration 6 --
137: string(5) "-10.5"
138: string(5) "-10.5"
139: string(5) "-10.5"
140:
141: -- Iteration 7 --
142: string(12) "101234567000"
143: string(12) "101234567000"
144: string(12) "101234567000"
145:
146: -- Iteration 8 --
147: string(13) "1.07654321E-9"
148: string(13) "1.07654321E-9"
149: string(13) "1.07654321E-9"
150:
151: -- Iteration 9 --
152: string(3) "0.5"
153: string(3) "0.5"
154: string(3) "0.5"
155:
156: -- Iteration 10 --
157:
158: Notice: Array to string conversion in %s on line %d
159: string(5) "Array"
160:
161: Notice: Array to string conversion in %s on line %d
162: string(5) "Array"
163:
164: Notice: Array to string conversion in %s on line %d
165: string(5) "Array"
166:
167: -- Iteration 11 --
168:
169: Notice: Array to string conversion in %s on line %d
170: string(5) "Array"
171:
172: Notice: Array to string conversion in %s on line %d
173: string(5) "Array"
174:
175: Notice: Array to string conversion in %s on line %d
176: string(5) "Array"
177:
178: -- Iteration 12 --
179:
180: Notice: Array to string conversion in %s on line %d
181: string(5) "Array"
182:
183: Notice: Array to string conversion in %s on line %d
184: string(5) "Array"
185:
186: Notice: Array to string conversion in %s on line %d
187: string(5) "Array"
188:
189: -- Iteration 13 --
190:
191: Notice: Array to string conversion in %s on line %d
192: string(5) "Array"
193:
194: Notice: Array to string conversion in %s on line %d
195: string(5) "Array"
196:
197: Notice: Array to string conversion in %s on line %d
198: string(5) "Array"
199:
200: -- Iteration 14 --
201:
202: Notice: Array to string conversion in %s on line %d
203: string(5) "Array"
204:
205: Notice: Array to string conversion in %s on line %d
206: string(5) "Array"
207:
208: Notice: Array to string conversion in %s on line %d
209: string(5) "Array"
210:
211: -- Iteration 15 --
212: string(0) ""
213: string(0) ""
214: string(0) ""
215:
216: -- Iteration 16 --
217: string(0) ""
218: string(0) ""
219: string(0) ""
220:
221: -- Iteration 17 --
222: string(1) "1"
223: string(1) "1"
224: string(1) "1"
225:
226: -- Iteration 18 --
227: string(0) ""
228: string(0) ""
229: string(0) ""
230:
231: -- Iteration 19 --
232: string(1) "1"
233: string(1) "1"
234: string(1) "1"
235:
236: -- Iteration 20 --
237: string(0) ""
238: string(0) ""
239: string(0) ""
240:
241: -- Iteration 21 --
242: string(0) ""
243: string(0) ""
244: string(0) ""
245:
246: -- Iteration 22 --
247: string(0) ""
248: string(0) ""
249: string(0) ""
250:
251: -- Iteration 23 --
252: string(6) "Object"
253: string(6) "Object"
254: string(6) "Object"
255:
256: -- Iteration 24 --
257: string(0) ""
258: string(0) ""
259: string(0) ""
260:
261: -- Iteration 25 --
262: string(0) ""
263: string(0) ""
264: string(0) ""
265:
266: -- Iteration 26 --
267: string(%d) "Resource id #%d"
268: string(%d) "Resource id #%d"
269: string(%d) "Resource id #%d"
270: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>