SplFixedArray and typed data structures: when PHP builtins waste memory
Regular PHP arrays are hash maps under the hood. Each element carries significant overhead (key hash, value zval, next pointer). For large integer-indexed arrays this wastes memory.
Comparison:
Run this in the sandbox to see the actual numbers.
In PHP 8+ the internal array representation improved significantly. The gap between SplFixedArray and plain array narrowed. Worth benchmarking on your actual PHP version rather than relying on old numbers.
SplMinHeap, SplMaxHeap, SplStack, SplQueue are all worth knowing. For priority queues SplMinHeap is significantly faster than sorting an array on each insert.
For purely numeric data (coordinates, timestamps, sensor readings), pack/unpack with binary strings is the most memory-efficient. The tradeoff is more complex access code.
I tried SplFixedArray in production for a 500k element dataset and it caused issues because some array functions (array_map, array_filter) do not work on SplFixedArray. Had to convert back and forth which erased the memory savings.
That is the main practical problem. SplFixedArray does not implement all array interfaces. If your code uses array_* functions extensively, the conversion overhead often exceeds the savings. Generators or chunking are usually a better trade-off.