xref: /PHP-7.4/ext/standard/tests/array/bug28974.phpt (revision 1f655451)
1--TEST--
2Bug #28974 (array_(p)slice() treats large lengths incorrectly - overflow)
3--FILE--
4<?php
5$a = $b = $c = array(0,1,2,3,4,5);
6print_r($a);
7// this is ok:
8print_r(array_slice($a,2,2147483645));
9
10// this is wrong:
11print_r(array_slice($a,2,2147483646));
12echo 'print_r(array_splice($a,2,1));'."\n";
13print_r(array_splice($a,2,1));
14echo "\$a is :";
15print_r($a);
16echo 'print_r(array_splice($b,2,2147483645));'."\n";
17print_r(array_splice($b,2,2147483645));
18echo "\$b is :";
19print_r($b);
20
21// this is wrong:
22echo 'print_r(array_splice($c,2,2147483646));'."\n";
23print_r(array_splice($c,2,2147483646));
24echo "\$c is :";
25print_r($c);
26?>
27--EXPECT--
28Array
29(
30    [0] => 0
31    [1] => 1
32    [2] => 2
33    [3] => 3
34    [4] => 4
35    [5] => 5
36)
37Array
38(
39    [0] => 2
40    [1] => 3
41    [2] => 4
42    [3] => 5
43)
44Array
45(
46    [0] => 2
47    [1] => 3
48    [2] => 4
49    [3] => 5
50)
51print_r(array_splice($a,2,1));
52Array
53(
54    [0] => 2
55)
56$a is :Array
57(
58    [0] => 0
59    [1] => 1
60    [2] => 3
61    [3] => 4
62    [4] => 5
63)
64print_r(array_splice($b,2,2147483645));
65Array
66(
67    [0] => 2
68    [1] => 3
69    [2] => 4
70    [3] => 5
71)
72$b is :Array
73(
74    [0] => 0
75    [1] => 1
76)
77print_r(array_splice($c,2,2147483646));
78Array
79(
80    [0] => 2
81    [1] => 3
82    [2] => 4
83    [3] => 5
84)
85$c is :Array
86(
87    [0] => 0
88    [1] => 1
89)
90