From: Operating system: irrelevant PHP version: Irrelevant Package: SPL related Bug Type: Feature/Change Request Bug description:SplFixedArray throws generic exceptions.
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 bug report at https://bugs.php.net/bug.php?id=60341&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=60341&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=60341&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=60341&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=60341&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=60341&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=60341&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=60341&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=60341&r=needscript Try newer version: https://bugs.php.net/fix.php?id=60341&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=60341&r=support Expected behavior: https://bugs.php.net/fix.php?id=60341&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=60341&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=60341&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=60341&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=60341&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=60341&r=dst IIS Stability: https://bugs.php.net/fix.php?id=60341&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=60341&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=60341&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=60341&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=60341&r=mysqlcfg