Req #60341 [Opn->Asn]: SplFixedArray should throw specific exceptions.
| From: | felipe@php.net | Date: | Mon, 21 Nov 2011 20:15:34 +0000 |
| Subject: | Req #60341 [Opn->Asn]: SplFixedArray should throw specific exceptions. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-165412@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=60341&edit=1
ID: 60341
Updated by: felipe@php.net
Reported by: morrison dot levi at gmail dot com
Summary: SplFixedArray should throw specific exceptions.
-Status: Open
+Status: Assigned
Type: Feature/Change Request
Package: SPL related
Operating System: irrelevant
PHP Version: 5.3
-Assigned To:
+Assigned To: colder
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[2011-11-21 17:36:11] morrison dot levi at gmail dot com
This should really be titled 'SplFixedArray should throw specific exceptions'
------------------------------------------------------------------------
[2011-11-19 21:31:32] morrison dot levi at gmail dot com
Description:
------------
SplFixedArray thankfully throws exceptions when you try to do incorrect things
with indices. However, the types of exceptions are just too generic. If I give
the wrong type of index, that's a logic error (I'd expect InvalidArgument or at
least something that inherits from LogicError to be thrown). If I give an index
that's that's a valid type but doesn't exist, I'd expect an OutOfBoundsException
to be thrown. Instead I get a generic RuntimeException.
I should expect because they are very different problems that I would at least
get a distinguishing message between the two. However, I get the same
descriptions: 'Index invalid or out of range'. The very message suggests they
should be different exceptions.
The first fix would sort-of break backwards compatibility: throw an
InvalidArgumentException for things of the wrong type.
The second fix, throw OutOfBoundsException on incorrect index, could be
implemented and keep backwards compatibility.
Test script:
---------------
$fa = new SplFixedArray(1);
$fa[new StdClass()]; //expect InvalidArgumentException or perhaps OutOfRangeException
$fa[2] = 'james'; // expect OutOfBoundsException
Expected result:
----------------
I expect $fa[new StdClass] to throw an InvalidArgumentException, not a
RuntimeException
I expect $fa['2'] to throw OutOfBoundsException not a RuntimeException.
Actual result:
--------------
Both throw RuntimeExceptions.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=60341&edit=1