public function count($mode = COUNT_NORMAL) { for ($i = 0; true; $i++) { if (!isset($this->{$i})) { return $i; } if ($mode === COUNT_RECURSIVE) { if ($this->{$i} instanceof \Countable) { $i += count($this->{$i}); } } } return $i; }