*/ public array $children; public bool $isEndOfWord; public function __construct() { $this->children = []; // Associative array where [ char => TrieNode ] $this->isEndOfWord = false; } /** * Add a child node for a character. */ public function addChild(string $char): TrieNode { $char = $this->normalizeChar($char); if (!isset($this->children[$char])) { $this->children[$char] = new TrieNode(); } return $this->children[$char]; } /** * Check if a character has a child node. */ public function hasChild(string $char): bool { $char = $this->normalizeChar($char); return isset($this->children[$char]); } /** * Get the child node corresponding to a character. */ public function getChild(string $char): ?TrieNode { $char = $this->normalizeChar($char); return $this->children[$char] ?? null; } /** * Normalize the character to lowercase. */ private function normalizeChar(string $char): string { return strtolower($char); } }