1--TEST--
2Test vfprintf() function : usage variations - string formats with non-string values
3--FILE--
4<?php
5/* Prototype  : int vfprintf  ( resource $handle  , string $format , array $args  )
6 * Description: Write a formatted string to a stream
7 * Source code: ext/standard/formatted_print.c
8*/
9
10/*
11 * Test vfprintf() when different string formats and non-string values are passed to
12 * the '$format' and '$args' arguments of the function
13*/
14
15error_reporting(E_ALL & ~E_NOTICE);
16
17echo "*** Testing vfprintf() : string formats and non-string values ***\n";
18
19// defining array of string formats
20$formats =
21  '%s %+s %-s
22   %ls %Ls %4s %-4s
23   %10.4s %-10.4s %04s %04.4s
24   %\'#2s %\'2s %\'$2s %\'_2s
25   %3$s %4$s %1$s %2$s';
26
27// Arrays of non string values for the format defined in $format.
28// Each sub array contains non string values which correspond to each format in $format
29$args_array = array(
30
31  // array of float values
32  array(2.2, .2, 10.2,
33        123456.234, 123456.234, -1234.6789, +1234.6789,
34        2.1234567e10, +2.7654321e10, -2.7654321e10,
35        12345.780, 12.000000011111, -12.00000111111, -123456.234,
36        3.33, +4.44, 1.11,-2.22 ),
37
38 // array of int values
39 array(2, -2, +2,
40       123456, 123456234, -12346789, +12346789,
41       123200, +20000, -40000, 22212,
42       12345780, 1211111, -12111111, -12345634,
43       3, +4, 1,-2 ),
44
45
46  // different arrays
47  array( array(0), array(1, 2), array(-1, -1),
48         array("123"), array('123'), array('-123'), array("-123"),
49         array(true), array(false), array(TRUE), array(FALSE),
50         array("123hello"), array("1", "2"), array('123hello'), array(12=>"12twelve"),
51         array("3"), array("4"), array("1"), array("2") ),
52
53  // array of boolean data
54  array( true, TRUE, false,
55         TRUE, 0, FALSE, 1,
56         true, false, TRUE, FALSE,
57         0, 1, 1, 0,
58         1, TRUE, 0, FALSE),
59
60);
61
62/* creating dumping file */
63$data_file = dirname(__FILE__) . '/dump.txt';
64if (!($fp = fopen($data_file, 'wt')))
65   return;
66
67// looping to test vfprintf() with different string formats from the above $format array
68// and with non-string values from the above $args_array array
69$counter = 1;
70foreach($args_array as $args) {
71  fprintf($fp, "\n-- Iteration %d --\n",$counter);
72  vfprintf($fp, $formats, $args);
73  $counter++;
74}
75
76fclose($fp);
77print_r(file_get_contents($data_file));
78echo "\n";
79
80unlink($data_file);
81
82?>
83===DONE===
84--EXPECT--
85*** Testing vfprintf() : string formats and non-string values ***
86
87-- Iteration 1 --
882.2 0.2 10.2
89   123456.234 s -1234.6789 1234.6789
90         2123 2765       -27654321000 1234
91   12.000000011111 -12.00000111111 -123456.234 3.33
92   10.2 123456.234 2.2 0.2
93-- Iteration 2 --
942 -2 2
95   123456 s -12346789 12346789
96         1232 2000       -40000 2221
97   12345780 1211111 -12111111 -12345634
98   2 123456 2 -2
99-- Iteration 3 --
100Array Array Array
101   Array s Array Array
102         Arra Arra       Array Arra
103   Array Array Array Array
104   Array Array Array Array
105-- Iteration 4 --
1061 1
107   1 s      1
108            1            0001 0000
109   #0 1 $1 _0
110    1 1 1
111===DONE===
112