From f031655f74846ce539f5a6048725461daa8be616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milan=20Mat=C4=9Bj=C4=8Dek?= Date: Thu, 10 Aug 2023 11:26:51 +0200 Subject: [PATCH] IgBinary: internally transform NULL to \x00 --- src/Driver/IgBinary.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Driver/IgBinary.php b/src/Driver/IgBinary.php index 800130a..36f78d1 100644 --- a/src/Driver/IgBinary.php +++ b/src/Driver/IgBinary.php @@ -7,6 +7,8 @@ final class IgBinary implements Driver { + private const NULL = "\x00"; + /** * @var array */ @@ -15,6 +17,9 @@ final class IgBinary implements Driver public static function encode($value): string { + if ($value === null) { + $value = self::NULL; + } $result = igbinary_serialize($value); if ($result === null) { $error = error_get_last(); @@ -38,13 +43,15 @@ public static function decode(string $value) } throw new InvalidStateException($error['message']); + } elseif ($data === self::NULL) { + return null; } return $data; } - private static function serializationCheckIgbinary(string $value): bool + public static function serializationCheckIgbinary(string $value): bool { return in_array(mb_substr($value, 0, 4), self::$haystack, true); }