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