diff --git a/UPGRADING b/UPGRADING index 7920c62ccecfc..b7966f599af69 100644 --- a/UPGRADING +++ b/UPGRADING @@ -39,6 +39,8 @@ PHP 8.3 UPGRADE NOTES inherited from the parent class. This will create a separate static property storage for the current class. This is analogous to adding the static property to the class directly without traits. + . Assigning a value to a negative index n in an empty array will now make + sure that the next index is n+1 and no longer default to 0. - FFI: . C functions that have a return type of void now return null instead of diff --git a/Zend/zend_hash.c b/Zend/zend_hash.c index 9c09dfdc274a6..e9525db95c51a 100644 --- a/Zend/zend_hash.c +++ b/Zend/zend_hash.c @@ -255,7 +255,7 @@ ZEND_API const HashTable zend_empty_array = { .nNumOfElements = 0, .nTableSize = HT_MIN_SIZE, .nInternalPointer = 0, - .nNextFreeElement = 0, + .nNextFreeElement = ZEND_LONG_MIN, .pDestructor = ZVAL_PTR_DTOR }; diff --git a/ext/standard/tests/array/negative_index_empty_array.phpt b/ext/standard/tests/array/negative_index_empty_array.phpt new file mode 100644 index 0000000000000..322ac6e820ce6 --- /dev/null +++ b/ext/standard/tests/array/negative_index_empty_array.phpt @@ -0,0 +1,18 @@ +--TEST-- +Test empty arrays with first added index being negative +--FILE-- + +--EXPECT-- +array(2) { + [-5]=> + string(2) "-5" + [-4]=> + string(8) "after -5" +}