Annotation of embedaddon/php/ext/standard/tests/strings/vprintf_variation1.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test vprintf() function : usage variations - unexpected values for the format argument
3: --FILE--
4: <?php
5: /* Prototype : string vprintf(string $format, array $args)
6: * Description: Output a formatted string
7: * Source code: ext/standard/formatted_print.c
8: */
9:
10: /*
11: * Test vprintf() when different unexpected format strings are passed to
12: * the '$format' argument of the function
13: */
14:
15: echo "*** Testing vprintf() : 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: /*1*/ 0,
41: 1,
42: 12345,
43: -2345,
44:
45: // float data
46: /*5*/ 10.5,
47: -10.5,
48: 10.1234567e10,
49: 10.7654321E-10,
50: .5,
51:
52: // array data
53: /*10*/ array(),
54: array(0),
55: array(1),
56: array(1,2),
57: array('color' => 'red', 'item' => 'pen'),
58:
59: // null data
60: /*15*/ NULL,
61: null,
62:
63: // boolean data
64: /*17*/ true,
65: false,
66: TRUE,
67: FALSE,
68:
69: // empty data
70: /*21*/ "",
71: '',
72:
73: // object data
74: /*23*/ new sample(),
75:
76: // undefined data
77: /*24*/ @$undefined_var,
78:
79: // unset data
80: /*25*/ @$unset_var,
81:
82: // resource data
83: /*26*/ $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: $result = vprintf($value,$args);
92: echo "\n";
93: var_dump($result);
94: $counter++;
95:
96: };
97:
98: // closing the resource
99: fclose($file_handle);
100:
101: ?>
102: ===DONE===
103: --EXPECTF--
104: *** Testing vprintf() : with unexpected values for format argument ***
105:
106: -- Iteration 1 --
107: 0
108: int(1)
109:
110: -- Iteration 2 --
111: 1
112: int(1)
113:
114: -- Iteration 3 --
115: 12345
116: int(5)
117:
118: -- Iteration 4 --
119: -2345
120: int(5)
121:
122: -- Iteration 5 --
123: 10.5
124: int(4)
125:
126: -- Iteration 6 --
127: -10.5
128: int(5)
129:
130: -- Iteration 7 --
131: 101234567000
132: int(12)
133:
134: -- Iteration 8 --
135: 1.07654321E-9
136: int(13)
137:
138: -- Iteration 9 --
139: 0.5
140: int(3)
141:
142: -- Iteration 10 --
143:
144: Notice: Array to string conversion in %s on line %d
145: Array
146: int(5)
147:
148: -- Iteration 11 --
149:
150: Notice: Array to string conversion in %s on line %d
151: Array
152: int(5)
153:
154: -- Iteration 12 --
155:
156: Notice: Array to string conversion in %s on line %d
157: Array
158: int(5)
159:
160: -- Iteration 13 --
161:
162: Notice: Array to string conversion in %s on line %d
163: Array
164: int(5)
165:
166: -- Iteration 14 --
167:
168: Notice: Array to string conversion in %s on line %d
169: Array
170: int(5)
171:
172: -- Iteration 15 --
173:
174: int(0)
175:
176: -- Iteration 16 --
177:
178: int(0)
179:
180: -- Iteration 17 --
181: 1
182: int(1)
183:
184: -- Iteration 18 --
185:
186: int(0)
187:
188: -- Iteration 19 --
189: 1
190: int(1)
191:
192: -- Iteration 20 --
193:
194: int(0)
195:
196: -- Iteration 21 --
197:
198: int(0)
199:
200: -- Iteration 22 --
201:
202: int(0)
203:
204: -- Iteration 23 --
205: object
206: int(6)
207:
208: -- Iteration 24 --
209:
210: int(0)
211:
212: -- Iteration 25 --
213:
214: int(0)
215:
216: -- Iteration 26 --
217: Resource id #%d
218: int(%d)
219: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>