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