Skip to content

Commit

Permalink
IgBinary: internally transform NULL to \x00
Browse files Browse the repository at this point in the history
  • Loading branch information
h4kuna committed Aug 10, 2023
1 parent e5c19c5 commit f031655
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Driver/IgBinary.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

final class IgBinary implements Driver
{
private const NULL = "\x00";

/**
* @var array<string>
*/
Expand All @@ -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();
Expand All @@ -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);
}
Expand Down

0 comments on commit f031655

Please sign in to comment.