rfc:spl-improvements:data-structures
This is an old revision of the document!
Request for Comments: SPL Improvements: Data Structures
- Version: 1.0
- Date: 2012-02-07
- Author: Levi Morrison levim@php.net
- Status: Work-in-progress
Introduction
The data structures in the SPL are flawed in many ways.
What is wrong with the data structures?
Inconsistent behavior between structures. The data-structures are inconsistent in how they act when in the same situation. Consider the following example where an SplDoublyLinkedList and an SplFixedArray encounter the same problem: an index greater than the size of the container was accessed.
<?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.
Poor API.
SplObjectStorage.
Proposal
We fix it.
Changelog
rfc/spl-improvements/data-structures.1326002056.txt.gz · Last modified: 2017/09/22 13:28 (external edit)