소스 검색

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.
Daniele Alessandri 8 년 전
부모
커밋
81c0a8f051
3개의 변경된 파일6개의 추가작업 그리고 3개의 파일을 삭제
  1. 2 1
      src/Connection/StreamConnection.php
  2. 2 1
      src/Protocol/Text/Handler/IntegerResponse.php
  3. 2 1
      src/Protocol/Text/ProtocolProcessor.php

+ 2 - 1
src/Connection/StreamConnection.php

@@ -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);

+ 2 - 1
src/Protocol/Text/Handler/IntegerResponse.php

@@ -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
src/Protocol/Text/ProtocolProcessor.php

@@ -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);