1--TEST--
2Test sprintf() function : Rope Optimization for '%d'.
3--FILE--
4<?php
5function func($num) {
6	return $num + 1;
7}
8function sideeffect() {
9	echo "Called!\n";
10	return "foo";
11}
12class Foo {
13	public function __construct() {
14		echo "Called\n";
15	}
16}
17
18$a = 42;
19$b = -1337;
20$c = 3.14;
21$d = new stdClass();
22
23try {
24	var_dump(sprintf("%d", $a));
25} catch (\Throwable $e) {echo $e, PHP_EOL; } echo PHP_EOL;
26
27try {
28	var_dump(sprintf("%d/%d", $a, $b));
29} catch (\Throwable $e) {echo $e, PHP_EOL; } echo PHP_EOL;
30
31try {
32	var_dump(sprintf("%d/%d/%d", $a, $b, $c));
33} catch (\Throwable $e) {echo $e, PHP_EOL; } echo PHP_EOL;
34
35try {
36	var_dump(sprintf("%d/%d/%d/%d", $a, $b, $c, $d));
37} catch (\Throwable $e) {echo $e, PHP_EOL; } echo PHP_EOL;
38
39try {
40	var_dump(sprintf("%d/", func(0)));
41} catch (\Throwable $e) {echo $e, PHP_EOL; } echo PHP_EOL;
42
43try {
44	var_dump(sprintf("/%d", func(0)));
45} catch (\Throwable $e) {echo $e, PHP_EOL; } echo PHP_EOL;
46
47try {
48	var_dump(sprintf("/%d/", func(0)));
49} catch (\Throwable $e) {echo $e, PHP_EOL; } echo PHP_EOL;
50
51try {
52	var_dump(sprintf("%d/%d/%d/%d", $a, $b, func(0), $a));
53} catch (\Throwable $e) {echo $e, PHP_EOL; } echo PHP_EOL;
54
55try {
56	var_dump(sprintf("%d/%d/%d/%d", __FILE__, __LINE__, 1, M_PI));
57} catch (\Throwable $e) {echo $e, PHP_EOL; } echo PHP_EOL;
58
59try {
60	var_dump(sprintf("%d/%d/%d", new Foo(), new Foo(), new Foo(), ));
61} catch (\Throwable $e) {echo $e, PHP_EOL; } echo PHP_EOL;
62
63try {
64	var_dump(sprintf('%d/%d/%d', [], [], []));
65} catch (\Throwable $e) {echo $e, PHP_EOL; } echo PHP_EOL;
66
67try {
68	if (PHP_INT_SIZE == 8) {
69		var_dump(sprintf('%d/%d/%d', PHP_INT_MAX, 0, PHP_INT_MIN));
70		var_dump("2147483647/0/-2147483648");
71	} else {
72		var_dump("9223372036854775807/0/-9223372036854775808");
73		var_dump(sprintf('%d/%d/%d', PHP_INT_MAX, 0, PHP_INT_MIN));
74	}
75} catch (\Throwable $e) {echo $e, PHP_EOL; } echo PHP_EOL;
76
77try {
78	var_dump(sprintf('%d/%d/%d', true, false, true));
79} catch (\Throwable $e) {echo $e, PHP_EOL; } echo PHP_EOL;
80
81try {
82	var_dump(sprintf("%d/%d", true, 'foo'));
83} catch (\Throwable $e) {echo $e, PHP_EOL; } echo PHP_EOL;
84
85try {
86	var_dump(sprintf("%d", 'foo'));
87} catch (\Throwable $e) {echo $e, PHP_EOL; } echo PHP_EOL;
88
89echo "Done";
90?>
91--EXPECTF--
92string(2) "42"
93
94string(8) "42/-1337"
95
96string(10) "42/-1337/3"
97
98
99Warning: Object of class stdClass could not be converted to int in %s on line 33
100string(12) "42/-1337/3/1"
101
102string(2) "1/"
103
104string(2) "/1"
105
106string(3) "/1/"
107
108string(13) "42/-1337/1/42"
109
110string(8) "0/53/1/3"
111
112Called
113Called
114Called
115
116Warning: Object of class Foo could not be converted to int in %s on line 57
117
118Warning: Object of class Foo could not be converted to int in %s on line 57
119
120Warning: Object of class Foo could not be converted to int in %s on line 57
121string(5) "1/1/1"
122
123string(5) "0/0/0"
124
125string(42) "9223372036854775807/0/-9223372036854775808"
126string(24) "2147483647/0/-2147483648"
127
128string(5) "1/0/1"
129
130string(3) "1/0"
131
132string(1) "0"
133
134Done
135