SplFixedArray implements Countable , but Countable does not accept arguments, so you cannot assume it is recursive. The argument is ignored. This can be seen from the signature of the SplFixedArray::count and Countable::count method.
There is a function request for this https://bugs.php.net/bug.php?id=58102
You can attach a SplFixedArray and make it an embedded RecursiveIterator , and then overload the count method to use iterate_count , but then it will always count all the elements, for example. it's always COUNT_RECURSIVE . You can also add a highlighted method.
class MySplFixedArray extends SplFixedArray implements RecursiveIterator { public function count() { return iterator_count( new RecursiveIteratorIterator( $this, RecursiveIteratorIterator::SELF_FIRST ) ); } public function getChildren() { return $this->current(); } public function hasChildren() { return $this->current() instanceof MySplFixedArray; } }
demo
source share