1--TEST--
2Test vfprintf() function : usage variations - char formats with non-char 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 char formats and non-char values are passed to
12 * the '$format' and '$args' arguments of the function
13*/
14
15echo "*** Testing vfprintf() : char formats and non-char values ***\n";
16
17// defining an array of various char formats
18$formats =
19  '%c %+c %-c
20   %lc %Lc %4c %-4c
21   %10.4c %-10.4c %04c %04.4c
22   %\'10c %\'10c %\'$10c %\'_10c
23   %3$c %4$c %1$c %2$c';
24
25// Arrays of non char values for the format defined in $format.
26// Each sub array contains non char values which correspond to each format in $format
27$args_array = array(
28
29  // array of float values
30  array(65.8, -65.8, +66.8,
31        93.2, -93.2, 126.8, -126.49,
32        35.44, -35.68, 32.99, -32.00,
33        -61.51, 61.51, 50.49, -54.50,
34        83.33, +84.44, 81.11, 82.22),
35
36  // array of int values
37  array(65, -65, +66,
38        169, -169, 126, -126,
39        35, -35, 32, -32,
40        -61, 61, 50, -54,
41        83, +84, 81, 82),
42
43  // array of strings
44  array(" ", ' ', 'hello',
45        '123hello', "123hello", '-123hello', '+123hello',
46        "\12345678hello", "-\12345678hello", '0123456hello', 'h123456ello',
47        "1234hello", "hello\0world", "NULL", "true",
48        "3", "4", '1', '2'),
49
50  // different arrays
51  array( array(0), array(1, 2), array(-1, -1),
52         array("123"), array('123'), array('-123'), array("-123"),
53         array(true), array(false), array(TRUE), array(FALSE),
54         array("123hello"), array("1", "2"), array('123hello'), array(12=>"12twelve"),
55         array("3"), array("4"), array("1"), array("2") ),
56
57  // array of boolean data
58  array( true, TRUE, false,
59         TRUE, 0, FALSE, 1,
60         true, false, TRUE, FALSE,
61         0, 1, 1, 0,
62         1, TRUE, 0, FALSE),
63
64);
65
66/* creating dumping file */
67$data_file = dirname(__FILE__) . '/vfprintf_variation10.txt';
68if (!($fp = fopen($data_file, 'wt')))
69   return;
70
71// looping to test vfprintf() with different char formats from the above $format array
72// and with non-char values from the above $args_array array
73$counter = 1;
74foreach($args_array as $args) {
75  fprintf($fp, "\n-- Iteration %d --\n",$counter);
76  vfprintf($fp, $formats, $args);
77  $counter++;
78}
79
80fclose($fp);
81print_r(file_get_contents($data_file));
82echo "\n";
83
84unlink($data_file);
85
86?>
87===DONE===
88--EXPECT--
89*** Testing vfprintf() : char formats and non-char values ***
90
91-- Iteration 1 --
92A � B
93   ] c ~ �
94   # �   �
95   � = 2 �
96   B ] A �
97-- Iteration 2 --
98A � B
99   � c ~ �
100   # �   �
101   � = 2 �
102   B � A �
103-- Iteration 3 --
104� � �
105   { c � {
106   � � @ �
107   � � � �
108   � { � �
109-- Iteration 4 --
110  
111    c  
112      
113      
114      
115-- Iteration 5 --
116  �
117    c � 
118    �  �
119   �   �
120   �   
121===DONE===
122