Browse Source

Type cast potential string value to int

If you pass "timeout" as parameter in an url, the function parseDsn in StaticConfigTrait.php will interpret the value as string. This triggers a "type error" in stream_socket_client. Type casting the variable to int solves it.
Example url in StaticConfigTrait.php triggers the error:
$dsn = 'smtp://user:secret@localhost:25?timeout=30&client=null&tls=null';
Peter Härder 5 years ago
parent
commit
5da10bc41b
1 changed files with 2 additions and 2 deletions
  1. 2 2
      src/Network/Socket.php

+ 2 - 2
src/Network/Socket.php

@@ -167,7 +167,7 @@ class Socket
             $remoteSocketTarget,
             $errNum,
             $errStr,
-            $this->_config['timeout'],
+            (int)$this->_config['timeout'],
             $connectAs,
             $context
         );
@@ -186,7 +186,7 @@ class Socket
         $this->connected = is_resource($this->connection);
         if ($this->connected) {
             /** @psalm-suppress PossiblyNullArgument */
-            stream_set_timeout($this->connection, $this->_config['timeout']);
+            stream_set_timeout($this->connection, (int)$this->_config['timeout']);
         }
 
         return $this->connected;