diff --git a/UPGRADING b/UPGRADING index 6300cfbdf1734..0025999d80455 100644 --- a/UPGRADING +++ b/UPGRADING @@ -34,6 +34,12 @@ PHP 8.4 UPGRADE NOTES This is no longer the case as a consequence of the bugfixes for GH-12192, GH-12208, #55098. +- SPL: + . Out of bounds accesses in SplFixedArray now throw an exception of type + OutOfBoundsException instead of RuntimeException. As OutOfBoundsException + is a child class of RuntimeException, code that uses RuntimeException + continues to function. + - Standard: . round() now validates the value of the $mode parameter and throws a ValueError for invalid modes. Previously invalid modes would have been interpreted as diff --git a/ext/spl/spl_fixedarray.c b/ext/spl/spl_fixedarray.c index 95ab191b77824..04330caf83a8c 100644 --- a/ext/spl/spl_fixedarray.c +++ b/ext/spl/spl_fixedarray.c @@ -376,8 +376,7 @@ static zval *spl_fixedarray_object_read_dimension_helper(spl_fixedarray_object * } if (index < 0 || index >= intern->array.size) { - // TODO Change error message and use OutOfBound SPL Exception? - zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0); + zend_throw_exception(spl_ce_OutOfBoundsException, "Index invalid or out of range", 0); return NULL; } else { return &intern->array.elements[index]; @@ -425,8 +424,7 @@ static void spl_fixedarray_object_write_dimension_helper(spl_fixedarray_object * } if (index < 0 || index >= intern->array.size) { - // TODO Change error message and use OutOfBound SPL Exception? - zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0); + zend_throw_exception(spl_ce_OutOfBoundsException, "Index invalid or out of range", 0); return; } else { /* Fix #81429 */ @@ -465,8 +463,7 @@ static void spl_fixedarray_object_unset_dimension_helper(spl_fixedarray_object * } if (index < 0 || index >= intern->array.size) { - // TODO Change error message and use OutOfBound SPL Exception? - zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0); + zend_throw_exception(spl_ce_OutOfBoundsException, "Index invalid or out of range", 0); return; } else { zval_ptr_dtor(&(intern->array.elements[index])); diff --git a/ext/spl/tests/fixedarray_001.phpt b/ext/spl/tests/fixedarray_001.phpt index 0683555934d53..802a9b8f8b806 100644 --- a/ext/spl/tests/fixedarray_001.phpt +++ b/ext/spl/tests/fixedarray_001.phpt @@ -45,9 +45,9 @@ $a[0] = "valueNew"; var_dump($b[0]); ?> --EXPECT-- -RuntimeException: Index invalid or out of range +OutOfBoundsException: Index invalid or out of range TypeError: Cannot access offset of type string on SplFixedArray -RuntimeException: Index invalid or out of range +OutOfBoundsException: Index invalid or out of range string(6) "value0" string(6) "value2" string(6) "value3" diff --git a/ext/spl/tests/fixedarray_002.phpt b/ext/spl/tests/fixedarray_002.phpt index 0ee2dcb8ba11d..329fa57eacb16 100644 --- a/ext/spl/tests/fixedarray_002.phpt +++ b/ext/spl/tests/fixedarray_002.phpt @@ -69,11 +69,11 @@ var_dump(count($a), $a->getSize(), count($a) == $a->getSize()); ?> --EXPECT-- A::offsetSet -RuntimeException: Index invalid or out of range +OutOfBoundsException: Index invalid or out of range A::offsetGet TypeError: Cannot access offset of type string on SplFixedArray A::offsetUnset -RuntimeException: Index invalid or out of range +OutOfBoundsException: Index invalid or out of range A::offsetSet A::offsetSet A::offsetSet