I have a class that represents a collection entity : it has only one attribute, an array. This class implements \Countable
, \IteratorAggregate
, and the most important for this question, \ArrayAccess
.
But when using :
usort($collectionData, function($a, $b) {
return ($a->getPosition() > $b->getPosition());
});
I get the following catchable exception :
Warning: usort() expects parameter 1 to be array, object given in /home/alain/workspace/(...)n.php line 1057 (500 Internal Server Error)
I can trick using an intermediate variable :
$data = $collectionData->getData();
usort($data, function($a, $b) {
return ($a->getPosition() > $b->getPosition());
});
$collectionData->setData($data);
But wanted to know if there is an SPL interface that can pass through the array parameter type expectation of usort()
.