1--TEST--
2Implicit float to int conversions when float too large should warn, string offset variant
3--SKIPIF--
4<?php
5if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
6?>
7--FILE--
8<?php
9
10$float = 10e120;
11$string_float = (string) $float;
12
13var_dump((int) $float);
14var_dump((int) $string_float);
15
16$string = 'Here is some text for good measure';
17
18echo 'Attempt to read', \PHP_EOL;
19try {
20    echo 'Float', \PHP_EOL;
21    var_dump($string[10e120]);
22} catch (\TypeError) {
23    echo 'TypeError', \PHP_EOL;
24}
25try {
26    echo 'Float variable', \PHP_EOL;
27    var_dump($string[$float]);
28} catch (\TypeError) {
29    echo 'TypeError', \PHP_EOL;
30}
31try {
32    echo 'Float casted to string compile', \PHP_EOL;
33    var_dump($string[(string) 10e120]);
34} catch (\TypeError) {
35    echo 'TypeError', \PHP_EOL;
36}
37try {
38    echo 'Float string variable', \PHP_EOL;
39    var_dump($string[$string_float]);
40} catch (\TypeError) {
41    echo 'TypeError', \PHP_EOL;
42}
43
44echo 'Attempt to assign', \PHP_EOL;
45try {
46    echo 'Float', \PHP_EOL;
47    $string[10e120] = 'E';
48    var_dump($string);
49    $string = 'Here is some text for good measure';
50} catch (\TypeError) {
51    echo 'TypeError', \PHP_EOL;
52}
53try {
54    echo 'Float variable', \PHP_EOL;
55    $string[$float] = 'E';
56    var_dump($string);
57    $string = 'Here is some text for good measure';
58} catch (\TypeError) {
59    echo 'TypeError', \PHP_EOL;
60}
61
62try {
63    $string[(string) 10e120] = 'E';
64    var_dump($string);
65} catch (\TypeError) {
66    echo 'TypeError', \PHP_EOL;
67}
68var_dump($string);
69try {
70    $string[$string_float] = 'E';
71} catch (\TypeError) {
72    echo 'TypeError', \PHP_EOL;
73}
74var_dump($string);
75
76?>
77--EXPECTF--
78int(0)
79int(9223372036854775807)
80Attempt to read
81Float
82
83Warning: String offset cast occurred in %s on line %d
84string(1) "H"
85Float variable
86
87Warning: String offset cast occurred in %s on line %d
88string(1) "H"
89Float casted to string compile
90TypeError
91Float string variable
92TypeError
93Attempt to assign
94Float
95
96Warning: String offset cast occurred in %s on line %d
97string(34) "Eere is some text for good measure"
98Float variable
99
100Warning: String offset cast occurred in %s on line %d
101string(34) "Eere is some text for good measure"
102TypeError
103string(34) "Here is some text for good measure"
104TypeError
105string(34) "Here is some text for good measure"
106