-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Throw from SplObjectStorage::current() for invalid iterator
Accessing key()/current() on an invalid iterator is an error condition. Throw instead of returning null.
- Loading branch information
Showing
2 changed files
with
11 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
--TEST-- | ||
Check that SplObjectStorage::current returns NULL when storage is empty | ||
Check that SplObjectStorage::current() throws when iterator invalid | ||
--CREDITS-- | ||
PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com) | ||
--FILE-- | ||
<?php | ||
|
||
$s = new SplObjectStorage(); | ||
|
||
var_dump($s->current()); | ||
var_dump($s->valid()); | ||
try { | ||
var_dump($s->current()); | ||
} catch (RuntimeException $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
NULL | ||
bool(false) | ||
Called current() on invalid iterator |