File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2227,6 +2227,9 @@ static uint32_t assign_dim_array_result_type(
22272227 if (dim_type & (MAY_BE_UNDEF |MAY_BE_NULL )) {
22282228 tmp |= MAY_BE_ARRAY_KEY_STRING ;
22292229 }
2230+ if ((tmp & MAY_BE_ARRAY_KEY_STRING ) && MAY_BE_PACKED (arr_type )) {
2231+ tmp |= MAY_BE_ARRAY_NUMERIC_HASH ;
2232+ }
22302233 }
22312234 }
22322235 /* Only add value type if we have a key type. It might be that the key type is illegal
@@ -3622,6 +3625,9 @@ static zend_always_inline zend_result _zend_update_type_info(
36223625 if (t2 & (MAY_BE_UNDEF | MAY_BE_NULL )) {
36233626 key_type |= MAY_BE_ARRAY_KEY_STRING ;
36243627 }
3628+ if ((key_type & MAY_BE_ARRAY_KEY_STRING ) && MAY_BE_PACKED (t1 )) {
3629+ key_type |= MAY_BE_ARRAY_NUMERIC_HASH ;
3630+ }
36253631 }
36263632 } else if (opline -> opcode == ZEND_FETCH_DIM_UNSET ) {
36273633 if (t1 & MAY_BE_ARRAY ) {
Original file line number Diff line number Diff line change 1+ --TEST--
2+ JIT: string key write turns a packed array into a hash with integer keys (function JIT)
3+ --INI--
4+ opcache.enable=1
5+ opcache.enable_cli=1
6+ opcache.file_update_protection=0
7+ opcache.jit_buffer_size=64M
8+ opcache.jit=function
9+ --EXTENSIONS--
10+ opcache
11+ --FILE--
12+ <?php
13+ function f () {
14+ $ arr = [10 , 11 ];
15+ for ($ i = 2 ; $ i >= 0 ; $ i --) {
16+ $ arr ['b ' ] = true ;
17+ echo $ i , ": \n" ;
18+ var_dump ($ arr [$ i ]);
19+ }
20+ }
21+ f ();
22+ ?>
23+ --EXPECTF--
24+ 2:
25+
26+ Warning: Undefined array key 2 in %s on line %d
27+ NULL
28+ 1:
29+ int(11)
30+ 0:
31+ int(10)
Original file line number Diff line number Diff line change 1+ --TEST--
2+ JIT: compound string key assignment turns a packed array into a hash with integer keys
3+ --INI--
4+ opcache.enable=1
5+ opcache.enable_cli=1
6+ opcache.file_update_protection=0
7+ opcache.jit_buffer_size=64M
8+ opcache.jit=function
9+ --EXTENSIONS--
10+ opcache
11+ --FILE--
12+ <?php
13+ function f () {
14+ $ arr = [1 , 2 , 3 ];
15+ $ arr ["a " ] += 1 ;
16+ var_dump ($ arr [1 ]);
17+ }
18+ f ();
19+ ?>
20+ --EXPECTF--
21+ Warning: Undefined array key "a" in %s on line %d
22+ int(2)
Original file line number Diff line number Diff line change 1+ --TEST--
2+ JIT: nested string key write turns a packed array into a hash with integer keys (tracing JIT)
3+ --INI--
4+ opcache.enable=1
5+ opcache.enable_cli=1
6+ opcache.file_update_protection=0
7+ opcache.jit_buffer_size=64M
8+ opcache.jit=tracing
9+ --EXTENSIONS--
10+ opcache
11+ --FILE--
12+ <?php
13+ function f ($ c ) {
14+ $ arr = [0 => 'x ' , 5 => 'y ' ];
15+ $ arr ['a ' ][32 ] = 1 ;
16+ $ r = 0 ;
17+ for ($ i = 0 ; $ i < 100 ; $ i ++) {
18+ $ r += isset ($ arr [0 ][$ c ]);
19+ }
20+ var_dump ($ r );
21+ }
22+ for ($ k = 0 ; $ k < 3 ; $ k ++) {
23+ f (0 );
24+ }
25+ ?>
26+ --EXPECT--
27+ int(100)
28+ int(100)
29+ int(100)
You can’t perform that action at this time.
0 commit comments