Skip to content

Commit b4d7ee9

Browse files
committed
Use a proper Error to signal that [] cannot be used with SplFixedArray
1 parent 7de1b30 commit b4d7ee9

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

ext/spl/spl_fixedarray.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ static zval *spl_fixedarray_object_read_dimension_helper(spl_fixedarray_object *
348348
/* we have to return NULL on error here to avoid memleak because of
349349
* ZE duplicating uninitialized_zval_ptr */
350350
if (!offset) {
351-
zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0);
351+
zend_throw_error(NULL, "[] operator not supported for SplFixedArray");
352352
return NULL;
353353
}
354354

@@ -400,7 +400,7 @@ static void spl_fixedarray_object_write_dimension_helper(spl_fixedarray_object *
400400

401401
if (!offset) {
402402
/* '$array[] = value' syntax is not supported */
403-
zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0);
403+
zend_throw_error(NULL, "[] operator not supported for SplFixedArray");
404404
return;
405405
}
406406

ext/spl/tests/fixedarray_004.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ $a = new SplFixedArray(10);
77

88
try {
99
$a[] = 1;
10-
} catch (Exception $e) {
11-
var_dump($e->getMessage());
10+
} catch (Error $e) {
11+
echo $e->getMessage(), "\n";
1212
}
1313

1414
?>
1515
--EXPECT--
16-
string(29) "Index invalid or out of range"
16+
[] operator not supported for SplFixedArray

ext/spl/tests/fixedarray_006.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ try {
1010
for ($i = 0; $i < 100; $i++) {
1111
$a[] = new stdClass;
1212
}
13-
} catch (Exception $e) {
13+
} catch (Error $e) {
1414
echo $e->getMessage(), "\n";
1515
}
1616

1717
print "ok\n";
1818

1919
?>
2020
--EXPECT--
21-
Index invalid or out of range
21+
[] operator not supported for SplFixedArray
2222
ok

ext/spl/tests/fixedarray_012.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ $a = new SplFixedArray(100);
77

88
try {
99
$b = &$a[];
10-
} catch (Exception $e) {
10+
} catch (Error $e) {
1111
echo $e->getMessage(), "\n";
1212
}
1313

1414
print "ok\n";
1515

1616
?>
1717
--EXPECT--
18-
Index invalid or out of range
18+
[] operator not supported for SplFixedArray
1919
ok

ext/spl/tests/fixedarray_013.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ function test(SplFixedArray &$arr) {
1212

1313
try {
1414
test($a[]);
15-
} catch (Exception $e) {
15+
} catch (\Error $e) {
1616
echo $e->getMessage(), "\n";
1717
}
1818

1919
?>
2020
--EXPECT--
21-
Index invalid or out of range
21+
[] operator not supported for SplFixedArray

0 commit comments

Comments
 (0)