The data structures in the SPL are flawed in many ways. See spl-improvements for more information on the SPL.
<?php try { $linkedList = new SplDoublyLinkedList(); $linkedList[1]; } catch(Exception $error) { echo get_class($error) . ': ' . $error->getMessage(). "\n"; } try { $fixedArray = new SplFixedArray(); $fixedArray[1]; } catch(Exception $error) { echo get_class($error) . ': ' . $error->getMessage(). "\n"; } ?>
The result:
OutOfRangeException: Offset invalid or out of range RuntimeException: Index invalid or out of range
They do not throw the same exception. Furthermore, SplDoublyLinkedList throws an exception that inherits from LogicException when it is not a logical exception but a runtime one.
<?php $linkedList = new SplDoublyLinkedList(); try { $linkedList[1]; } catch(Exception $error) { echo get_class($error) . ': ' . $error->getMessage() . "\n"; } try { $linkedList[new StdClass()] = 'class'; } catch(Exception $error) { echo get_class($error) . ': ' . $error->getMessage() . "\n"; } try { $linkedList->pop(); } catch(Exception $error) { echo get_class($error) . ': ' . $error->getMessage() . "\n"; } ?>
The result:
OutOfRangeException: Offset invalid or out of range OutOfRangeException: Offset invalid or out of range RuntimeException: Can't pop from an empty datastructure