rfc:spl-improvements:data-structures
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
rfc:spl-improvements:data-structures [2012/01/08 05:52] – created levim | rfc:spl-improvements:data-structures [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 8: | Line 8: | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | The data structures in the SPL are flawed in many ways. | + | The data structures in the SPL are flawed in many ways. See [[/ |
+ | ===== What is wrong with the data structures? ===== | ||
- | ===== What is wrong with the data structures? ----- | + | * **The data-structures |
+ | * <code php><?php | ||
+ | try { | ||
+ | $linkedList = new SplDoublyLinkedList(); | ||
+ | $linkedList[1]; | ||
+ | } catch(Exception $error) { | ||
+ | echo get_class($error) . ': ' . $error-> | ||
+ | } | ||
+ | try { | ||
+ | $fixedArray = new SplFixedArray(); | ||
+ | $fixedArray[1]; | ||
+ | } catch(Exception $error) { | ||
+ | echo get_class($error) . ': ' . $error-> | ||
+ | } | ||
+ | ?></ | ||
+ | RuntimeException: | ||
+ | * **The data-structures do not throw the most appropriate and specific exceptions they can.** | ||
+ | $linkedList = new SplDoublyLinkedList(); | ||
- | Inconsistent behavior between structures. | + | try { |
+ | $linkedList[1]; | ||
+ | } catch(Exception $error) { | ||
+ | echo get_class($error) | ||
+ | } | ||
- | Poor API. | + | try { |
+ | $linkedList[new StdClass()] = ' | ||
+ | } catch(Exception $error) { | ||
+ | echo get_class($error) | ||
+ | } | ||
- | SplObjectStorage. | + | try { |
+ | $linkedList-> | ||
+ | } catch(Exception $error) { | ||
+ | echo get_class($error) . ': ' . $error-> | ||
+ | } | ||
+ | ?></ | ||
+ | OutOfRangeException: | ||
+ | RuntimeException: | ||
+ | - Accessing an out-of-bounds index led to an incorrect exception type of OutOfRangeException, | ||
+ | - Trying to set an index using an invalid type (a class) led to an OutOfRangeException. | ||
+ | - Popping from an empty container caused a generic RuntimeException to be thrown. | ||
+ | * **[[http:// | ||
+ | |||
+ | * [[http:// | ||
===== Proposal ===== | ===== Proposal ===== | ||
- | We fix it. | + | * **SplStack and SplQueue should not publicly inherit from SplDoublyLinkedList.** |
+ | * **SplObjectStorage should be split into a Map(Dictionary) and Set.** | ||
===== Changelog ===== | ===== Changelog ===== |
rfc/spl-improvements/data-structures.1326001940.txt.gz · Last modified: 2017/09/22 13:28 (external edit)