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