Skip to content

Commit 04a2a42

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Revert "Fix GH-10008: Narrowing occurred during type inference of ZEND_ADD_ARRAY_ELEMENT"
2 parents df89409 + 0f5b382 commit 04a2a42

File tree

3 files changed

+9
-55
lines changed

3 files changed

+9
-55
lines changed

NEWS

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.3.0RC4
44

5-
- Core:
6-
. Fixed bug GH-10008 (Narrowing occurred during type inference of
7-
ZEND_ADD_ARRAY_ELEMENT). (nielsdos, arnaud-lb)
8-
95
- CType:
106
. Fixed bug GH-11997 (ctype_alnum 5 times slower in PHP 8.1 or greater).
117
(nielsdos)

Zend/Optimizer/zend_inference.c

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,21 +1942,6 @@ ZEND_API uint32_t zend_array_element_type(uint32_t t1, uint8_t op_type, int writ
19421942
return tmp;
19431943
}
19441944

1945-
static zend_always_inline uint32_t assign_long_dim_array_result_type(uint32_t arr_type)
1946-
{
1947-
/* Rules:
1948-
* HASH_ONLY -> MAY_BE_ARRAY_NUMERIC_HASH
1949-
* PACKED_ONLY -> MAY_BE_ARRAY_NUMERIC_HASH | MAY_BE_ARRAY_PACKED (== MAY_BE_ARRAY_KEY_LONG)
1950-
* HASH || PACKED -> MAY_BE_ARRAY_NUMERIC_HASH | MAY_BE_ARRAY_PACKED (== MAY_BE_ARRAY_KEY_LONG)
1951-
* 0 -> MAY_BE_ARRAY_NUMERIC_HASH
1952-
*/
1953-
if (MAY_BE_PACKED(arr_type)) {
1954-
return MAY_BE_ARRAY_KEY_LONG;
1955-
} else {
1956-
return MAY_BE_ARRAY_NUMERIC_HASH;
1957-
}
1958-
}
1959-
19601945
static uint32_t assign_dim_array_result_type(
19611946
uint32_t arr_type, uint32_t dim_type, uint32_t value_type, uint8_t dim_op_type) {
19621947
uint32_t tmp = 0;
@@ -1970,13 +1955,13 @@ static uint32_t assign_dim_array_result_type(
19701955
if (arr_type & (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE)) {
19711956
tmp |= MAY_BE_ARRAY_PACKED;
19721957
}
1973-
tmp |= assign_long_dim_array_result_type(arr_type);
1958+
tmp |= MAY_BE_HASH_ONLY(arr_type) ? MAY_BE_ARRAY_NUMERIC_HASH : MAY_BE_ARRAY_KEY_LONG;
19741959
} else {
19751960
if (dim_type & (MAY_BE_LONG|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_RESOURCE|MAY_BE_DOUBLE)) {
19761961
if (arr_type & (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE)) {
19771962
tmp |= MAY_BE_ARRAY_PACKED;
19781963
}
1979-
tmp |= assign_long_dim_array_result_type(arr_type);
1964+
tmp |= MAY_BE_HASH_ONLY(arr_type) ? MAY_BE_ARRAY_NUMERIC_HASH : MAY_BE_ARRAY_KEY_LONG;
19801965
}
19811966
if (dim_type & MAY_BE_STRING) {
19821967
tmp |= MAY_BE_ARRAY_KEY_STRING;
@@ -1985,7 +1970,7 @@ static uint32_t assign_dim_array_result_type(
19851970
if (arr_type & (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE)) {
19861971
tmp |= MAY_BE_ARRAY_PACKED;
19871972
}
1988-
tmp |= assign_long_dim_array_result_type(arr_type);
1973+
tmp |= MAY_BE_HASH_ONLY(arr_type) ? MAY_BE_ARRAY_NUMERIC_HASH : MAY_BE_ARRAY_KEY_LONG;
19891974
}
19901975
}
19911976
if (dim_type & (MAY_BE_UNDEF|MAY_BE_NULL)) {
@@ -3305,15 +3290,17 @@ static zend_always_inline zend_result _zend_update_type_info(
33053290
key_type |= MAY_BE_ARRAY_PACKED;
33063291
}
33073292
if (t1 & MAY_BE_ARRAY) {
3308-
key_type |= assign_long_dim_array_result_type(t1);
3293+
key_type |= MAY_BE_HASH_ONLY(t1) ?
3294+
MAY_BE_ARRAY_NUMERIC_HASH : MAY_BE_ARRAY_KEY_LONG;
33093295
}
33103296
} else {
33113297
if (t2 & (MAY_BE_LONG|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_RESOURCE|MAY_BE_DOUBLE)) {
33123298
if (t1 & (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE)) {
33133299
key_type |= MAY_BE_ARRAY_PACKED;
33143300
}
33153301
if (t1 & MAY_BE_ARRAY) {
3316-
key_type |= assign_long_dim_array_result_type(t1);
3302+
key_type |= MAY_BE_HASH_ONLY(t1) ?
3303+
MAY_BE_ARRAY_NUMERIC_HASH : MAY_BE_ARRAY_KEY_LONG;
33173304
}
33183305
}
33193306
if (t2 & MAY_BE_STRING) {
@@ -3324,7 +3311,8 @@ static zend_always_inline zend_result _zend_update_type_info(
33243311
key_type |= MAY_BE_ARRAY_PACKED;
33253312
}
33263313
if (t1 & MAY_BE_ARRAY) {
3327-
key_type |= assign_long_dim_array_result_type(t1);
3314+
key_type |= MAY_BE_HASH_ONLY(t1) ?
3315+
MAY_BE_ARRAY_NUMERIC_HASH : MAY_BE_ARRAY_KEY_LONG;
33283316
}
33293317
}
33303318
}

ext/opcache/tests/opt/gh10008.phpt

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)