diff --git a/src/Postcode.php b/src/Postcode.php index 377391b..cfffc2b 100644 --- a/src/Postcode.php +++ b/src/Postcode.php @@ -317,7 +317,7 @@ public function split() * * @return string */ - public function __toString() + public function __toString(): string { return (string) $this->normalise(); } @@ -346,6 +346,24 @@ public function unserialize($serialized) return $this->value; } + /** + * Generates a storable representation of a value + * + */ + public function __serialize(): array + { + return [$this->value]; + } + + /** + * Creates a PHP value from a stored representation + * + */ + public function __unserialize(array $serialized): void + { + $this->value = $serialized[0]; + } + /** * Specify data which should be serialized to JSON @@ -353,6 +371,7 @@ public function unserialize($serialized) * @return mixed data which can be serialized by json_encode, * @link http://php.net/manual/en/jsonserializable.jsonserialize.php */ + #[\ReturnTypeWillChange] public function jsonSerialize() { return [