Terry Djony
Terry Djony

Reputation: 2015

Custom iteration for SplObjectStorage

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

Answers (1)

JayTaph
JayTaph

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

Related Questions