1--TEST--
2Test vprintf() function : usage variations - octal formats with non-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 non-octal values are passed to
16 * the '$format' and '$args' arguments of the function
17*/
18
19echo "*** Testing vprintf() : octal formats and non-octal values ***\n";
20
21// defining array of octal formats
22$formats =
23  '%o %+o %-o
24   %lo %Lo %4o %-4o
25   %10.4o %-10.4o %.4o
26   %\'#2o %\'2o %\'$2o %\'_2o
27   %3$o %4$o %1$o %2$o';
28
29// Arrays of non octal values for the format defined in $format.
30// Each sub array contains non octal values which correspond to each format in $format
31$args_array = array(
32
33  // array of float values
34  array(2.2, .2, 10.2,
35        123456.234, 123456.234, -1234.6789, +1234.6789,
36        2e10, +2e12, 22e+12,
37        12345.780, 12.000000011111, -12.00000111111, -123456.234,
38        3.33, +4.44, 1.11,-2.22 ),
39
40  // array of int values
41  array(2, -2, +2,
42        123456, 123456234, -12346789, +12346789,
43        123200, +20000, 22212,
44        12345780, 1211111, -12111111, -12345634,
45        3, +4, 1,-2 ),
46
47  // array of strings
48  array(" ", ' ', 'hello',
49        '123hello', "123hello", '-123hello', '+123hello',
50        "\12345678hello", "-\12345678hello", 'h123456ello',
51        "1234hello", "hello\0world", "NULL", "true",
52        "3", "4", '1', '2'),
53
54  // different arrays
55  array( array(0), array(1, 2), array(-1, -1),
56         array("123"), array('123'), array('-123'), array("-123"),
57         array(true), array(false), array(FALSE),
58         array("123hello"), array("1", "2"), array('123hello'), array(12=>"12twelve"),
59         array("3"), array("4"), array("1"), array("2") ),
60
61  // array of boolean data
62  array( true, TRUE, false,
63         TRUE, 0, FALSE, 1,
64         true, false, TRUE,
65         0, 1, 1, 0,
66         1, TRUE, 0, FALSE),
67
68);
69
70// looping to test vprintf() with different octal formats from the above $format array
71// and with non-octal values from the above $args_array array
72$counter = 1;
73foreach($args_array as $args) {
74  echo "\n-- Iteration $counter --\n";
75  $result = vprintf($formats, $args);
76  echo "\n";
77  var_dump($result);
78  $counter++;
79}
80
81?>
82===DONE===
83--EXPECT--
84*** Testing vprintf() : octal formats and non-octal values ***
85
86-- Iteration 1 --
872 0 12
88   361100 o 37777775456 2322
89
90   30071 14 37777777764 37777416700
91   12 361100 2 0
92int(116)
93
94-- Iteration 2 --
952 37777777776 2
96   361100 o 37720715133 57062645
97
98   57060664 4475347 37721631371 37720717336
99   2 361100 2 37777777776
100int(146)
101
102-- Iteration 3 --
1030 0 0
104   173 o 37777777605 173
105
106   2322 0 $0 _0
107   0 173 0 0
108int(88)
109
110-- Iteration 4 --
1111 1 1
112   1 o    1 1
113
114   #1 1 $1 _1
115   1 1 1 1
116int(75)
117
118-- Iteration 5 --
1191 1 0
120   1 o    0 1
121
122   #0 1 $1 _0
123   0 1 1 1
124int(75)
125===DONE===
126