Why are just a few PHP array functions are available in ArrayObject class as method? For example asort() is available but walk() and many others are not.
$s= new ArrayObject(array(1,3,4,5,6,4));
$x= $s->asort(); //implemented
$x= $s->sum(); //not implemented
$x= array_sum($s->getArrayCopy()); //not an OO manner!
//sum is an example, consider:array_map,array_walk,array_merge ....
Please note that I have carefully read the documentation. My question is WHY php team just embedded a subset of array functions in ArrayObject class (that should encapsulate array related requirments). Isn’t it a poor design?
Why we should extend this class and embed tens of function in this class again? Is is reasonable?
Think about what a collection of objects should be able to do natively and easily. If I have a collection of books, I want to be able to sort them, I want to be able to get one at a certain location, I want to be able to iterate through them, etc. What I don’t want is to be able to add them all up. If I added a sum function to that object, it would mean that every instance of that object would also have a sum function — a bizarre and unexpected use case for the most part.
ArrayObject, in a lot of senses, is a lot closer to the idea of the traditional array than PHP’sarrayever managed. I believe it is supposed to be faster because of this.