I have this class:
class ResultSet
implements ArrayAccess, Countable, Iterator {
/// Rest of implementation ...
}
I’m running into a problem using usort() and passing my object as the first parameter. usort() expects an array instead of an object, but given my implementation of the ArrayAccess interface I don’t know what else it could be needing.
The exact error returned by php is:
Warning: usort() expects parameter 1 to be array, object given.
How would
usortknow how you’ve implementedArrayAccess? There is no defined place where the values are kept — that flexibility is the whole point of the interface.If you are storing the elements in an array that is a private member of the object, you could proxy the
usortoperation. For example: