Ensure big ints are not truncated on 32 bits PHP.

We check if the string value is different than the casted int value,
if so it means that the integer is beyond PHP_INT_MAX or PHP_INT_MIN
and we simply return the string value. This is also useful on Windows
builds of PHP since the maximum integer size (prior to PHP 7.0) is 32
bits even for 64 bit builds.
This commit is contained in:
Daniele Alessandri
2016-06-01 23:49:23 +02:00
parent 1065edc8d1
commit 81c0a8f051
3 changed files with 6 additions and 3 deletions
+2 -1
View File
@@ -360,7 +360,8 @@ class StreamConnection extends AbstractConnection
return $multibulk;
case ':':
return (int) $payload;
$integer = (int) $payload;
return $integer == $payload ? $integer : $payload;
case '-':
return new ErrorResponse($payload);
@@ -31,7 +31,8 @@ class IntegerResponse implements ResponseHandlerInterface
public function handle(CompositeConnectionInterface $connection, $payload)
{
if (is_numeric($payload)) {
return (int) $payload;
$integer = (int) $payload;
return $integer == $payload ? $integer : $payload;
}
if ($payload !== 'nil') {
+2 -1
View File
@@ -90,7 +90,8 @@ class ProtocolProcessor implements ProtocolProcessorInterface
return $multibulk;
case ':':
return (int) $payload;
$integer = (int) $payload;
return $integer == $payload ? $integer : $payload;
case '-':
return new ErrorResponse($payload);