1--TEST--
2Verifying that the str_increment() polyfill behaves the same
3--FILE--
4<?php
5
6function polyfill(string $s): string {
7    if (is_numeric($s)) {
8        $offset = stripos($s, 'e');
9        if ($offset !== false) {
10            /* Using increment operator would cast the string to float
11             * Therefore we manually increment it to convert it to an "f"/"F" that doesn't get affected */
12            $c = $s[$offset];
13            $c++;
14            $s[$offset] = $c;
15            $s++;
16            $s[$offset] = match ($s[$offset]) {
17                'f' => 'e',
18                'F' => 'E',
19                'g' => 'f',
20                'G' => 'F',
21            };
22            return $s;
23        }
24    }
25    return ++$s;
26}
27
28$strictlyAlphaNumeric = [
29    "Az",
30    "aZ",
31    "A9",
32    "a9",
33    // Carrying values until the beginning of the string
34    "Zz",
35    "zZ",
36    "9z",
37    "9Z",
38    // string interpretable as a number in scientific notation
39    "5e6",
40    "5E6",
41    "5e9",
42    "5E9",
43    // Interned strings
44    "d",
45    "D",
46    "4",
47];
48
49foreach ($strictlyAlphaNumeric as $s) {
50    if (str_increment($s) !== polyfill($s)) {
51        var_dump("Error:", str_increment($s), polyfill($s));
52    }
53}
54
55echo "DONE";
56
57?>
58--EXPECT--
59DONE
60