Skip to content

Convert bounds exception in SplFixedArray to OutOfBoundsException instead of RuntimeException #12383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions ext/spl/spl_fixedarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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]));
Expand Down
4 changes: 2 additions & 2 deletions ext/spl/tests/fixedarray_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions ext/spl/tests/fixedarray_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down