File tree Expand file tree Collapse file tree 5 files changed +30
-28
lines changed Expand file tree Collapse file tree 5 files changed +30
-28
lines changed Original file line number Diff line number Diff line change @@ -3,23 +3,23 @@ Next free element may overflow in array literals
3
3
--FILE--
4
4
<?php
5
5
6
- $ i = PHP_INT_MAX ;
7
- $ array = [$ i => 42 , new stdClass ];
8
- var_dump ($ array );
6
+ try {
7
+ $ i = PHP_INT_MAX ;
8
+ $ array = [$ i => 42 , new stdClass ];
9
+ var_dump ($ array );
10
+ } catch (\Error $ e ) {
11
+ echo $ e ->getMessage () . "\n" ;
12
+ }
9
13
10
- const FOO = [PHP_INT_MAX => 42 , "foo " ];
11
- var_dump (FOO );
14
+ try {
15
+ const FOO = [PHP_INT_MAX => 42 , "foo " ];
16
+ var_dump (FOO );
17
+ } catch (\Error $ e ) {
18
+ echo $ e ->getMessage () . "\n" ;
19
+ }
12
20
13
21
?>
14
- --EXPECTF--
15
- Warning: Cannot add element to the array as the next element is already occupied in %s on line %d
16
- array(1) {
17
- [%d]=>
18
- int(42)
19
- }
22
+ --EXPECT--
23
+ Cannot add element to the array as the next element is already occupied
24
+ Cannot add element to the array as the next element is already occupied
20
25
21
- Warning: Cannot add element to the array as the next element is already occupied in %s on line %d
22
- array(1) {
23
- [%d]=>
24
- int(42)
25
- }
Original file line number Diff line number Diff line change @@ -12,7 +12,11 @@ function test() {
12
12
var_dump ($ array [new stdClass ] = 123 );
13
13
var_dump ($ true [123 ] = 456 );
14
14
15
- var_dump ($ array [] += 123 );
15
+ try {
16
+ var_dump ($ array [] += 123 );
17
+ } catch (\Error $ e ) {
18
+ echo $ e ->getMessage () . "\n" ;
19
+ }
16
20
var_dump ($ array [[]] += 123 );
17
21
var_dump ($ array [new stdClass ] += 123 );
18
22
var_dump ($ true [123 ] += 456 );
36
40
37
41
Warning: Cannot use a scalar value as an array in %s on line %d
38
42
NULL
39
-
40
- Warning: Cannot add element to the array as the next element is already occupied in %s on line %d
41
- NULL
43
+ Cannot add element to the array as the next element is already occupied
42
44
43
45
Warning: Illegal offset type in %s on line %d
44
46
NULL
Original file line number Diff line number Diff line change @@ -4,12 +4,15 @@ Bug #47836 (array operator [] inconsistency when the array has PHP_INT_MAX index
4
4
<?php
5
5
6
6
$ arr [PHP_INT_MAX ] = 1 ;
7
- $ arr [] = 2 ;
8
-
7
+ try {
8
+ $ arr [] = 2 ;
9
+ } catch (\Error $ e ) {
10
+ echo $ e ->getMessage () . "\n" ;
11
+ }
9
12
var_dump ($ arr );
10
13
?>
11
- --EXPECTF --
12
- Warning: Cannot add element to the array as the next element is already occupied in %s on line 4
14
+ --EXPECT --
15
+ Cannot add element to the array as the next element is already occupied
13
16
array(1) {
14
17
[%d]=>
15
18
int(1)
Original file line number Diff line number Diff line change @@ -18,6 +18,3 @@ var_dump($y[]++);
18
18
NULL
19
19
NULL
20
20
NULL
21
- NULL
22
- NULL
23
- NULL
Original file line number Diff line number Diff line change @@ -1968,7 +1968,7 @@ static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_scalar_as_array(v
1968
1968
1969
1969
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_cannot_add_element (void )
1970
1970
{
1971
- zend_error ( E_WARNING , "Cannot add element to the array as the next element is already occupied" );
1971
+ zend_throw_error ( NULL , "Cannot add element to the array as the next element is already occupied" );
1972
1972
}
1973
1973
1974
1974
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_resource_as_offset (const zval * dim )
You can’t perform that action at this time.
0 commit comments