1--TEST--
2Using different sorts of numerical strings as a string offset
3--FILE--
4<?php
5
6$str = "The world is fun";
7
8$keys = [
9    "7",
10    "7.5",
11    "  7",
12    "  7.5",
13    "  7  ",
14    "  7.5  ",
15    "7  ",
16    "7.5  ",
17    "7str",
18    "7.5str",
19    "  7str",
20    "  7.5str",
21    "  7  str",
22    "  7.5  str",
23    "7  str",
24    "7.5  str",
25    "0xC",
26    "0b10",
27    "07",
28];
29
30foreach ($keys as $key) {
31    try {
32        var_dump($str[$key]);
33    } catch (\TypeError $e) {
34        echo $e->getMessage() . \PHP_EOL;
35    }
36}
37
38echo "Done\n";
39?>
40--EXPECTF--
41string(1) "l"
42Cannot access offset of type string on string
43string(1) "l"
44Cannot access offset of type string on string
45string(1) "l"
46Cannot access offset of type string on string
47string(1) "l"
48Cannot access offset of type string on string
49
50Warning: Illegal string offset "7str" in %s on line %d
51string(1) "l"
52Cannot access offset of type string on string
53
54Warning: Illegal string offset "  7str" in %s on line %d
55string(1) "l"
56Cannot access offset of type string on string
57
58Warning: Illegal string offset "  7  str" in %s on line %d
59string(1) "l"
60Cannot access offset of type string on string
61
62Warning: Illegal string offset "7  str" in %s on line %d
63string(1) "l"
64Cannot access offset of type string on string
65
66Warning: Illegal string offset "0xC" in %s on line %d
67string(1) "T"
68
69Warning: Illegal string offset "0b10" in %s on line %d
70string(1) "T"
71string(1) "l"
72Done
73