1--TEST--
2Star width and precision in sprintf()
3--FILE--
4<?php
5
6
7$f = 1.23456789012345678;
8$fx = 1.23456789012345678e100;
9var_dump($f, $fx);
10
11printf("%.*f\n", 10, $f);
12printf("%.*G\n", 10, $f);
13printf("%.*g\n", -1, $fx);
14printf("%.*G\n", -1, $fx);
15printf("%.*h\n", -1, $fx);
16printf("%.*H\n", -1, $fx);
17printf("%.*s\n", 3, "foobar");
18echo "\n";
19
20printf("%*f\n", 10, $f);
21printf("%*G\n", 10, $f);
22printf("%*s\n", 10, "foobar");
23echo "\n";
24
25printf("%*.*f\n", 10, 3, $f);
26printf("%*.*G\n", 10, 3, $f);
27printf("%*.*s\n", 10, 3, "foobar");
28echo "\n";
29
30printf("%1$.*2\$f\n", $f, 10);
31printf("%.*2\$f\n", $f, 10);
32printf("%2$.*f\n", 10, $f);
33printf("%1$*2\$f\n", $f, 10);
34printf("%*2\$f\n", $f, 10);
35printf("%2$*f\n", 10, $f);
36printf("%1$*2$.*3\$f\n", $f, 10, 3);
37printf("%*2$.*3\$f\n", $f, 10, 3);
38printf("%3$*.*f\n", 10, 3, $f);
39echo "\n";
40
41try {
42    printf("%.*G\n", "foo", 1.5);
43} catch (ValueError $e) {
44    echo $e->getMessage(), "\n";
45}
46
47try {
48    printf("%.*G\n", -100, 1.5);
49} catch (ValueError $e) {
50    echo $e->getMessage(), "\n";
51}
52
53try {
54    printf("%.*s\n", -1, "Foo");
55} catch (ValueError $e) {
56    echo $e->getMessage(), "\n";
57}
58
59try {
60    printf("%*G\n", -1, $f);
61} catch (ValueError $e) {
62    echo $e->getMessage(), "\n";
63}
64
65?>
66--EXPECT--
67float(1.2345678901234567)
68float(1.2345678901234569E+100)
691.2345678901
701.23456789
711.2345678901234569e+100
721.2345678901234569E+100
731.2345678901234569e+100
741.2345678901234569E+100
75foo
76
77  1.234568
78   1.23457
79    foobar
80
81     1.235
82      1.23
83       foo
84
851.2345678901
861.2345678901
871.2345678901
88  1.234568
89  1.234568
90  1.234568
91     1.235
92     1.235
93     1.235
94
95Precision must be an integer
96Precision must be between -1 and 2147483647
97Precision -1 is only supported for %g, %G, %h and %H
98Width must be greater than zero and less than 2147483647
99