1--TEST--
2Test vprintf() function : usage variations - octal formats with octal values
3--SKIPIF--
4<?php
5if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
6?>
7--FILE--
8<?php
9/* Prototype  : string vprintf(string format, array args)
10 * Description: Output a formatted string
11 * Source code: ext/standard/formatted_print.c
12*/
13
14/*
15 * Test vprintf() when different octal formats and octal values are passed to
16 * the '$format' and '$args' arguments of the function
17*/
18
19echo "*** Testing vprintf() : octal formats with octal values ***\n";
20
21// defining array of octal formats
22$formats = array(
23  "%o",
24  "%+o %-o %O",
25  "%lo %Lo, %4o %-4o",
26  "%10.4o %-10.4o %04o %04.4o",
27  "%'#2o %'2o %'$2o %'_2o",
28  "%o %o %o %o",
29  "%% %%o %10 o%",
30  '%3$o %4$o %1$o %2$o'
31);
32
33// Arrays of octal values for the format defined in $format.
34// Each sub array contains octal values which correspond to each format string in $format
35$args_array = array(
36  array(00),
37  array(-01, 01, +022),
38  array(-020000000000, 020000000000, 017777777777, -017777777777),
39  array(0123456, 012345678, -01234567, 01234567),
40  array(0111, 02222, -0333333, -044444444),
41  array(0x123b, 0xfAb, 0123, 01293),
42  array(01234, 05678, -01234, 02345),
43  array(03, 04, 01, 02)
44
45);
46
47// looping to test vprintf() with different octal formats from the above $formats array
48// and with octal values from the above $args_array array
49$counter = 1;
50foreach($formats as $format) {
51  echo "\n-- Iteration $counter --\n";
52  $result = vprintf($format, $args_array[$counter-1]);
53  echo "\n";
54  var_dump($result);
55  $counter++;
56}
57
58?>
59===DONE===
60--EXPECT--
61*** Testing vprintf() : octal formats with octal values ***
62
63-- Iteration 1 --
640
65int(1)
66
67-- Iteration 2 --
6837777777777 1
69int(14)
70
71-- Iteration 3 --
7220000000000 o, 17777777777 20000000001
73int(38)
74
75-- Iteration 4 --
76                      37776543211 0000
77int(38)
78
79-- Iteration 5 --
80111 2222 37777444445 37733333334
81int(32)
82
83-- Iteration 6 --
8411073 7653 123 12
85int(17)
86
87-- Iteration 7 --
88% %o o
89int(6)
90
91-- Iteration 8 --
921 2 3 4
93int(7)
94===DONE===
95