1--TEST--
2Test range() function with unexpected string inputs
3--INI--
4serialize_precision=14
5--FILE--
6<?php
7
8echo "Range will ignore any byte after the first one\n";
9var_dump( range("AA", "BB") );
10
11echo "Range cannot operate on an empty string\n";
12var_dump( range("Z", "") ); // Both strings are cast to int, i.e. 0
13var_dump( range("", "Z") ); // Both strings are cast to int, i.e. 0
14
15echo "Mixing numeric float string and character\n";
16var_dump( range("3.5", "A") ); // The char is cast to a float, i.e. 0
17var_dump( range("?", "3.5") ); // The char is cast to a float, i.e. 0
18
19echo "Fractional step cannot be used on character ranges\n";
20var_dump( range("A", "H", 2.6) ); // Because step is fractional it tries to interpret inputs as floats
21
22echo "Done\n";
23?>
24--EXPECTF--
25Range will ignore any byte after the first one
26
27Warning: range(): Argument #1 ($start) must be a single byte, subsequent bytes are ignored in %s on line %d
28
29Warning: range(): Argument #2 ($end) must be a single byte, subsequent bytes are ignored in %s on line %d
30array(2) {
31  [0]=>
32  string(1) "A"
33  [1]=>
34  string(1) "B"
35}
36Range cannot operate on an empty string
37
38Warning: range(): Argument #2 ($end) must not be empty, casted to 0 in %s on line %d
39
40Warning: 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 in %s on line %d
41array(1) {
42  [0]=>
43  int(0)
44}
45
46Warning: range(): Argument #1 ($start) must not be empty, casted to 0 in %s on line %d
47
48Warning: range(): Argument #1 ($start) must be a single byte string if argument #2 ($end) is a single byte string, argument #2 ($end) converted to 0 in %s on line %d
49array(1) {
50  [0]=>
51  int(0)
52}
53Mixing numeric float string and character
54
55Warning: range(): Argument #1 ($start) must be a single byte string if argument #2 ($end) is a single byte string, argument #2 ($end) converted to 0 in %s on line %d
56array(4) {
57  [0]=>
58  float(3.5)
59  [1]=>
60  float(2.5)
61  [2]=>
62  float(1.5)
63  [3]=>
64  float(0.5)
65}
66
67Warning: 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 in %s on line %d
68array(4) {
69  [0]=>
70  float(0)
71  [1]=>
72  float(1)
73  [2]=>
74  float(2)
75  [3]=>
76  float(3)
77}
78Fractional step cannot be used on character ranges
79
80Warning: range(): Argument #3 ($step) must be of type int when generating an array of characters, inputs converted to 0 in %s on line %d
81array(1) {
82  [0]=>
83  float(0)
84}
85Done
86