the century the two-digit year belongs to. */ private const array CENTURIES = [ '+' => 1800, '-' => 1900, 'Y' => 1900, 'X' => 1900, 'W' => 1900, 'V' => 1900, 'U' => 1900, 'A' => 2000, 'B' => 2000, 'C' => 2000, 'D' => 2000, 'E' => 2000, 'F' => 2000, ]; public string $value; public function __construct(string $value) { $value = strtoupper(preg_replace('/\s+/', '', $value) ?? $value); if (preg_match('/^(\d{2})(\d{2})(\d{2})([-+A-FU-Y])(\d{3})([0-9A-Y])$/', $value, $parts) !== 1) { throw new InvalidPersonalIdentityCode; } [, $day, $month, $year, $centurySign, $individualNumber, $checkCharacter] = $parts; if (! checkdate((int) $month, (int) $day, self::CENTURIES[$centurySign] + (int) $year)) { throw new InvalidPersonalIdentityCode; } $expected = self::CHECK_CHARACTERS[(int) ($day.$month.$year.$individualNumber) % 31]; if ($checkCharacter !== $expected) { throw new InvalidPersonalIdentityCode; } $this->value = $value; } /** * The code with the date of birth hidden, e.g. ••••••-308T. */ public function masked(): string { return '••••••'.substr($this->value, 6); } public function equals(self $other): bool { return $this->value === $other->value; } }