1--TEST--
2Test sprintf() function : usage variations - octal formats with array values
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
10echo "*** Testing sprintf() : octal formats with array values ***\n";
11
12// different arrays used to test the function
13$array_values = array(
14  array(),
15  array(0),
16  array(1),
17  array(NULL),
18  array(null),
19  array("string"),
20  array(true),
21  array(TRUE),
22  array(false),
23  array(FALSE),
24  array(1,2,3,4),
25  array(0123),
26  array(1 => "One", "two" => 2)
27);
28
29// array of octal formats
30$octal_formats = array(
31  "%o", "%ho", "%lo",
32  "%Lo", " %o", "%o ",
33  "\t%o", "\n%o", "%4o",
34  "%30o", "%[0-7]", "%*o"
35);
36
37$count = 1;
38foreach($array_values as $array_value) {
39  echo "\n-- Iteration $count --\n";
40
41  foreach($octal_formats as $format) {
42    var_dump( sprintf($format, $array_value) );
43  }
44  $count++;
45};
46
47echo "Done";
48?>
49--EXPECTF--
50*** Testing sprintf() : octal formats with array values ***
51
52-- Iteration 1 --
53string(1) "0"
54string(1) "o"
55string(1) "0"
56string(1) "o"
57string(2) " 0"
58string(2) "0 "
59string(2) "	0"
60string(2) "
610"
62string(4) "   0"
63string(30) "                             0"
64string(4) "0-7]"
65string(1) "o"
66
67-- Iteration 2 --
68string(1) "1"
69string(1) "o"
70string(1) "1"
71string(1) "o"
72string(2) " 1"
73string(2) "1 "
74string(2) "	1"
75string(2) "
761"
77string(4) "   1"
78string(30) "                             1"
79string(4) "0-7]"
80string(1) "o"
81
82-- Iteration 3 --
83string(1) "1"
84string(1) "o"
85string(1) "1"
86string(1) "o"
87string(2) " 1"
88string(2) "1 "
89string(2) "	1"
90string(2) "
911"
92string(4) "   1"
93string(30) "                             1"
94string(4) "0-7]"
95string(1) "o"
96
97-- Iteration 4 --
98string(1) "1"
99string(1) "o"
100string(1) "1"
101string(1) "o"
102string(2) " 1"
103string(2) "1 "
104string(2) "	1"
105string(2) "
1061"
107string(4) "   1"
108string(30) "                             1"
109string(4) "0-7]"
110string(1) "o"
111
112-- Iteration 5 --
113string(1) "1"
114string(1) "o"
115string(1) "1"
116string(1) "o"
117string(2) " 1"
118string(2) "1 "
119string(2) "	1"
120string(2) "
1211"
122string(4) "   1"
123string(30) "                             1"
124string(4) "0-7]"
125string(1) "o"
126
127-- Iteration 6 --
128string(1) "1"
129string(1) "o"
130string(1) "1"
131string(1) "o"
132string(2) " 1"
133string(2) "1 "
134string(2) "	1"
135string(2) "
1361"
137string(4) "   1"
138string(30) "                             1"
139string(4) "0-7]"
140string(1) "o"
141
142-- Iteration 7 --
143string(1) "1"
144string(1) "o"
145string(1) "1"
146string(1) "o"
147string(2) " 1"
148string(2) "1 "
149string(2) "	1"
150string(2) "
1511"
152string(4) "   1"
153string(30) "                             1"
154string(4) "0-7]"
155string(1) "o"
156
157-- Iteration 8 --
158string(1) "1"
159string(1) "o"
160string(1) "1"
161string(1) "o"
162string(2) " 1"
163string(2) "1 "
164string(2) "	1"
165string(2) "
1661"
167string(4) "   1"
168string(30) "                             1"
169string(4) "0-7]"
170string(1) "o"
171
172-- Iteration 9 --
173string(1) "1"
174string(1) "o"
175string(1) "1"
176string(1) "o"
177string(2) " 1"
178string(2) "1 "
179string(2) "	1"
180string(2) "
1811"
182string(4) "   1"
183string(30) "                             1"
184string(4) "0-7]"
185string(1) "o"
186
187-- Iteration 10 --
188string(1) "1"
189string(1) "o"
190string(1) "1"
191string(1) "o"
192string(2) " 1"
193string(2) "1 "
194string(2) "	1"
195string(2) "
1961"
197string(4) "   1"
198string(30) "                             1"
199string(4) "0-7]"
200string(1) "o"
201
202-- Iteration 11 --
203string(1) "1"
204string(1) "o"
205string(1) "1"
206string(1) "o"
207string(2) " 1"
208string(2) "1 "
209string(2) "	1"
210string(2) "
2111"
212string(4) "   1"
213string(30) "                             1"
214string(4) "0-7]"
215string(1) "o"
216
217-- Iteration 12 --
218string(1) "1"
219string(1) "o"
220string(1) "1"
221string(1) "o"
222string(2) " 1"
223string(2) "1 "
224string(2) "	1"
225string(2) "
2261"
227string(4) "   1"
228string(30) "                             1"
229string(4) "0-7]"
230string(1) "o"
231
232-- Iteration 13 --
233string(1) "1"
234string(1) "o"
235string(1) "1"
236string(1) "o"
237string(2) " 1"
238string(2) "1 "
239string(2) "	1"
240string(2) "
2411"
242string(4) "   1"
243string(30) "                             1"
244string(4) "0-7]"
245string(1) "o"
246Done
247