Reputation: 2015
I want to modify the way to iterate an SPLObjectStorage object, such as sorting it first by the data (info).
So, in a loop, it goes numerically from a to z (using sort() function)
But, in SPLObjectStorage, there is no access to the array, right ?
Is it possible to do it since we don't have the access to the array of objects ??
Upvotes: 1
Views: 694
Reputation: 2916
No, it's not possible. Internally SplobjectStorage
use the same data structure as an array (the HashTable
), but it's not an "array-array" as we know from the PHP userland: we only add values and not keys, as keys are actually generated from the values by hashing them (you can even overwrite this by overwriting the getHash
method). Another difference is that you can additionally add information to the object.
In short, SplObjectStorage should not be used as an array, but as either a set or a map, there lies its strength.
Upvotes: 1