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

Description

When range() produces all the values between two boundaries. These two boundaries must be of the same type, for consistency purpose. Hence, when one is a one character string, the second one also needs to be a one character string, and range() generates all the values between these strings.

Example

<?php

range('c', 3);

?>

Literal Examples

  • 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

Solutions

  • Use another string as second argument.

  • Call range with two integers, and use chr() on each element of the array to turn them into characters.

Changed Behavior

This error may appear following an evolution in behavior, in previous versions. See rangeSingleByteString.