Zend certified PHP/Magento developer

Replace usage of array with aliased SPL classes

I’m not saying this is a good idea, but it’s an idea. 😉

Problem: array in PHP does not communicate intent well, especially it’s not clear if it’s a list or a hash map.

Solution: Run this:

use ArrayObject as dict; use SplDoublyLinkedList as dlist; // Better name? use SplFixedArray as vec; 

The point here is to use dict for hash maps, dlist for lists with unknown length, and vec for lists with fixed length.

class_alias cannot be run on built-in classes, so the only way to make the aliases global is to create dummy classes which inherit from them.

Of course it would be interesting to see how performance were affected. I assume memory consumption would go up a little bit, for the object initialization? Otherwise i expect it to be pretty much the same as for array, except for really, really big fixed-length arrays which have better performance.

(Possible solution to my ranty thread hear: https://old.reddit.com/r/PHP/comments/f9xmfg/splitting_array_into_list_and_dict/)

submitted by /u/usernameqwerty003
[link] [comments]