1--TEST--
2Implicit float to int conversions should warn for variables
3--FILE--
4<?php
5
6echo 'Bitwise ops:' . \PHP_EOL;
7
8$float = 1.5;
9
10$var = ~$float;
11var_dump($var);
12
13$var = $float|3;
14var_dump($var);
15
16$var = $float&3;
17var_dump($var);
18
19$var = $float^3;
20var_dump($var);
21
22$var = $float << 3;
23var_dump($var);
24
25$var = $float >> 3;
26var_dump($var);
27
28$var = $float;
29$var <<= 3;
30var_dump($var);
31
32$var = $float;
33$var >>= 3;
34var_dump($var);
35
36$var = 3 << $float;
37var_dump($var);
38
39$var = 3 >> $float;
40var_dump($var);
41
42echo 'Modulo:' . \PHP_EOL;
43$modFloat = 6.5;
44$var = $modFloat % 2;
45var_dump($var);
46
47$modFloat = 2.5;
48$var = 9 % $modFloat;
49var_dump($var);
50
51echo 'Offset access:' . \PHP_EOL;
52$offsetAccess = 2.5;
53echo 'Arrays:' . \PHP_EOL;
54// 2 warnings in total
55$array = ['a', 'b', 'c'];
56var_dump($array[$float]);
57$array[$offsetAccess] = 'z';
58var_dump($array);
59
60echo 'Strings:' . \PHP_EOL;
61// 2 warnings in total
62$string = 'php';
63var_dump($string[$float]);
64$string[$offsetAccess] = 'z';
65var_dump($string);
66
67echo 'Function calls:' . \PHP_EOL;
68function foo(int $a) {
69    return $a;
70}
71var_dump(foo($float));
72
73$cp = 60.5;
74var_dump(chr($cp));
75
76echo 'Function returns:' . \PHP_EOL;
77function bar(): int {
78    $var = 3.5;
79    return $var;
80}
81var_dump(bar());
82
83echo 'Typed property assignment:' . \PHP_EOL;
84class Test {
85    public int $a;
86}
87
88$instance = new Test();
89$instance->a = $float;
90var_dump($instance->a);
91
92?>
93--EXPECTF--
94Bitwise ops:
95
96Deprecated: Implicit conversion from float 1.5 to int loses precision in %s on line %d
97int(-2)
98
99Deprecated: Implicit conversion from float 1.5 to int loses precision in %s on line %d
100int(3)
101
102Deprecated: Implicit conversion from float 1.5 to int loses precision in %s on line %d
103int(1)
104
105Deprecated: Implicit conversion from float 1.5 to int loses precision in %s on line %d
106int(2)
107
108Deprecated: Implicit conversion from float 1.5 to int loses precision in %s on line %d
109int(8)
110
111Deprecated: Implicit conversion from float 1.5 to int loses precision in %s on line %d
112int(0)
113
114Deprecated: Implicit conversion from float 1.5 to int loses precision in %s on line %d
115int(8)
116
117Deprecated: Implicit conversion from float 1.5 to int loses precision in %s on line %d
118int(0)
119
120Deprecated: Implicit conversion from float 1.5 to int loses precision in %s on line %d
121int(6)
122
123Deprecated: Implicit conversion from float 1.5 to int loses precision in %s on line %d
124int(1)
125Modulo:
126
127Deprecated: Implicit conversion from float 6.5 to int loses precision in %s on line %d
128int(0)
129
130Deprecated: Implicit conversion from float 2.5 to int loses precision in %s on line %d
131int(1)
132Offset access:
133Arrays:
134
135Deprecated: Implicit conversion from float 1.5 to int loses precision in %s on line %d
136string(1) "b"
137
138Deprecated: Implicit conversion from float 2.5 to int loses precision in %s on line %d
139array(3) {
140  [0]=>
141  string(1) "a"
142  [1]=>
143  string(1) "b"
144  [2]=>
145  string(1) "z"
146}
147Strings:
148
149Warning: String offset cast occurred in %s on line %d
150string(1) "h"
151
152Warning: String offset cast occurred in %s on line %d
153string(3) "phz"
154Function calls:
155
156Deprecated: Implicit conversion from float 1.5 to int loses precision in %s on line %d
157int(1)
158
159Deprecated: Implicit conversion from float 60.5 to int loses precision in %s on line %d
160string(1) "<"
161Function returns:
162
163Deprecated: Implicit conversion from float 3.5 to int loses precision in %s on line %d
164int(3)
165Typed property assignment:
166
167Deprecated: Implicit conversion from float 1.5 to int loses precision in %s on line %d
168int(1)
169