link = $link; $this->hasChildren = $has_children; $this->depth = $depth; $this->subtree = $subtree; $this->inActiveTrail = $in_active_trail; } /** * Counts all menu links in the current subtree. * * @return int * The number of menu links in this subtree (one plus the number of menu * links in all descendants). */ public function count() { $sum = function ($carry, MenuLinkTreeElement $element) { return $carry + $element->count(); }; return 1 + array_reduce($this->subtree, $sum); } }