Skip to content

Commit 009d48d

Browse files
authored
Convert bounds exception in SplFixedArray to OutOfBoundsException instead of RuntimeException (#12383)
1 parent 0700313 commit 009d48d

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

UPGRADING

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ PHP 8.4 UPGRADE NOTES
3434
This is no longer the case as a consequence of the bugfixes for GH-12192,
3535
GH-12208, #55098.
3636

37+
- SPL:
38+
. Out of bounds accesses in SplFixedArray now throw an exception of type
39+
OutOfBoundsException instead of RuntimeException. As OutOfBoundsException
40+
is a child class of RuntimeException, code that uses RuntimeException
41+
continues to function.
42+
3743
- Standard:
3844
. round() now validates the value of the $mode parameter and throws a ValueError
3945
for invalid modes. Previously invalid modes would have been interpreted as

ext/spl/spl_fixedarray.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,7 @@ static zval *spl_fixedarray_object_read_dimension_helper(spl_fixedarray_object *
376376
}
377377

378378
if (index < 0 || index >= intern->array.size) {
379-
// TODO Change error message and use OutOfBound SPL Exception?
380-
zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0);
379+
zend_throw_exception(spl_ce_OutOfBoundsException, "Index invalid or out of range", 0);
381380
return NULL;
382381
} else {
383382
return &intern->array.elements[index];
@@ -425,8 +424,7 @@ static void spl_fixedarray_object_write_dimension_helper(spl_fixedarray_object *
425424
}
426425

427426
if (index < 0 || index >= intern->array.size) {
428-
// TODO Change error message and use OutOfBound SPL Exception?
429-
zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0);
427+
zend_throw_exception(spl_ce_OutOfBoundsException, "Index invalid or out of range", 0);
430428
return;
431429
} else {
432430
/* Fix #81429 */
@@ -465,8 +463,7 @@ static void spl_fixedarray_object_unset_dimension_helper(spl_fixedarray_object *
465463
}
466464

467465
if (index < 0 || index >= intern->array.size) {
468-
// TODO Change error message and use OutOfBound SPL Exception?
469-
zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0);
466+
zend_throw_exception(spl_ce_OutOfBoundsException, "Index invalid or out of range", 0);
470467
return;
471468
} else {
472469
zval_ptr_dtor(&(intern->array.elements[index]));

ext/spl/tests/fixedarray_001.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ $a[0] = "valueNew";
4545
var_dump($b[0]);
4646
?>
4747
--EXPECT--
48-
RuntimeException: Index invalid or out of range
48+
OutOfBoundsException: Index invalid or out of range
4949
TypeError: Cannot access offset of type string on SplFixedArray
50-
RuntimeException: Index invalid or out of range
50+
OutOfBoundsException: Index invalid or out of range
5151
string(6) "value0"
5252
string(6) "value2"
5353
string(6) "value3"

ext/spl/tests/fixedarray_002.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ var_dump(count($a), $a->getSize(), count($a) == $a->getSize());
6969
?>
7070
--EXPECT--
7171
A::offsetSet
72-
RuntimeException: Index invalid or out of range
72+
OutOfBoundsException: Index invalid or out of range
7373
A::offsetGet
7474
TypeError: Cannot access offset of type string on SplFixedArray
7575
A::offsetUnset
76-
RuntimeException: Index invalid or out of range
76+
OutOfBoundsException: Index invalid or out of range
7777
A::offsetSet
7878
A::offsetSet
7979
A::offsetSet

0 commit comments

Comments
 (0)