computeLength(); $result = parent::__toString(); $result .= $this->length ?? ''; return $result . $this->value; } public function getAdditionalInformation(): int { $this->computeLength(); return parent::getAdditionalInformation(); } public static function create(string $data): self { return new self($data); } public function getValue(): string { return $this->value; } public function getLength(): int { return strlen($this->value); } public function normalize(): string { return $this->value; } /** * A string object is immutable, so its head never changes -- but decoding never asks for it: the object is built * from the payload and read back through normalize(), and only re-encoding calls __toString(). Computing it up * front made every decoded string pay for a head nobody reads. */ private function computeLength(): void { if ($this->lengthComputed) { return; } [$this->additionalInformation, $this->length] = LengthCalculator::getLengthOfString($this->value); $this->lengthComputed = true; } }