Skip to content

Commit fb77ee0

Browse files
committed
Convert some SPL Exceptions to normal Errors in spl_observer.c
1 parent de41cf3 commit fb77ee0

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

ext/spl/spl_observer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static int spl_object_storage_get_hash(zend_hash_key *key, spl_SplObjectStorage
109109
key->key = Z_STR(rv);
110110
return SUCCESS;
111111
} else {
112-
zend_throw_exception(spl_ce_RuntimeException, "Hash needs to be a string", 0);
112+
zend_type_error("Hash needs to be a string");
113113

114114
zval_ptr_dtor(&rv);
115115
return FAILURE;
@@ -1023,7 +1023,7 @@ SPL_METHOD(MultipleIterator, attachIterator)
10231023
spl_SplObjectStorageElement *element;
10241024

10251025
if (Z_TYPE_P(info) != IS_LONG && Z_TYPE_P(info) != IS_STRING) {
1026-
zend_throw_exception(spl_ce_InvalidArgumentException, "Info must be NULL, integer or string", 0);
1026+
zend_type_error("Info must be NULL, integer or string");
10271027
RETURN_THROWS();
10281028
}
10291029

ext/spl/tests/SplObjectStorage_getHash.phpt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ $s = new SplObjectStorage();
66
$o1 = new Stdclass;
77
$o2 = new Stdclass;
88
$s[$o1] = "some_value\n";
9-
echo $s->offsetGet($o1);
9+
var_dump($s->offsetGet($o1));
1010

1111
class MySplObjectStorage extends SplObjectStorage {
1212
public function getHash($obj) {
@@ -17,8 +17,8 @@ class MySplObjectStorage extends SplObjectStorage {
1717
try {
1818
$s1 = new MySplObjectStorage;
1919
$s1[$o1] = "foo";
20-
} catch(Exception $e) {
21-
echo "caught\n";
20+
} catch (\TypeError $e) {
21+
echo $e->getMessage() . PHP_EOL;
2222
}
2323

2424
class MySplObjectStorage2 extends SplObjectStorage {
@@ -31,8 +31,8 @@ class MySplObjectStorage2 extends SplObjectStorage {
3131
try {
3232
$s2 = new MySplObjectStorage2;
3333
$s2[$o2] = "foo";
34-
} catch(Exception $e) {
35-
echo "caught\n";
34+
} catch (\Exception $e) {
35+
echo $e->getMessage() . PHP_EOL;
3636
}
3737

3838
class MySplObjectStorage3 extends SplObjectStorage {
@@ -49,10 +49,11 @@ $s3[$o2] = $o2;
4949
var_dump($s3[$o1] === $s3[$o2]);
5050

5151
?>
52-
--EXPECT--
53-
some_value
54-
caught
55-
caught
56-
object(stdClass)#2 (0) {
52+
--EXPECTF--
53+
string(11) "some_value
54+
"
55+
Hash needs to be a string
56+
foo
57+
object(stdClass)#%d (0) {
5758
}
5859
bool(true)

ext/spl/tests/multiple_iterator_001.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ foreach($m as $key => $value) {
7878
echo "-- Associate with invalid value --\n";
7979

8080
try {
81-
$m->attachIterator($iter3, new stdClass());
82-
} catch(InvalidArgumentException $e) {
83-
echo "InvalidArgumentException thrown: " . $e->getMessage() . "\n";
81+
$m->attachIterator($iter3, new stdClass());
82+
} catch (\TypeError $e) {
83+
echo $e->getMessage() . PHP_EOL;
8484
}
8585

8686
echo "-- Associate with duplicate value --\n";
@@ -297,7 +297,7 @@ array(3) {
297297
int(3)
298298
}
299299
-- Associate with invalid value --
300-
InvalidArgumentException thrown: Info must be NULL, integer or string
300+
Info must be NULL, integer or string
301301
-- Associate with duplicate value --
302302
InvalidArgumentException thrown: Key duplication error
303303
-- Count, contains, detach, count, contains, iterate --

0 commit comments

Comments
 (0)