range() Uses Single Byte Strings

When the first argument of range() is a single byte string, then the second argument must also be a single byte string, to keep the range consistent. Until PHP 8.3, the first string was converted to a integer too, most often 0, and then, the range was created.

PHP code

<?php

print_r(range('c', 3));

?>

Before

Array
(
    [0] => 0
    [1] => 1
    [2] => 2
    [3] => 3
)

After

PHP Warning:  range(): Argument #2 ($end) must be a single byte string if argument #1 ($start) is a single byte string, argument #1 ($start) converted to 0

Warning: range(): Argument #2 ($end) must be a single byte string if argument #1 ($start) is a single byte string, argument #1 ($start) converted to 0
Array
(
    [0] => 0
    [1] => 1
    [2] => 2
    [3] => 3
)

PHP version change

This behavior changed in 8.3

See Also

Error Messages