key = $key; $this->value = $value; $this->left = null; $this->right = null; $this->parent = null; } public function isRoot(): bool { return $this->parent === null; } public function isLeaf(): bool { return $this->left === null && $this->right === null; } public function getChildren(): array { if ($this->isLeaf()) { return []; } $children = []; if ($this->left !== null) { $children['left'] = $this->left; } if ($this->right !== null) { $children['right'] = $this->right; } return $children; } public function getChildrenCount(): int { return count($this->getChildren()); } }