Skip to content

Commit 3c8a5d6

Browse files
committed
Add explanation about StreamSelectLoop::getSeconds int overflow workaround.
1 parent 4347fa3 commit 3c8a5d6

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

‎src/StreamSelectLoop.php‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,15 @@ private function waitForStreamActivity($timeout)
222222
private static function getSeconds($time)
223223
{
224224
/*
225-
* Workaround for PHP int overflow:
226-
* (float)PHP_INT_MAX == PHP_INT_MAX => true
227-
* (int)(float)PHP_INT_MAX == PHP_INT_MAX => false
228-
* (int)(float)PHP_INT_MAX == PHP_INT_MIN => true
225+
* intval(floor($time)) will produce int overflow
226+
* if $time is (float)PHP_INT_MAX:
227+
* (float)PHP_INT_MAX == PHP_INT_MAX //true
228+
* (int)(float)PHP_INT_MAX == PHP_INT_MAX //false
229+
* (int)(float)PHP_INT_MAX == PHP_INT_MIN //true
230+
* -----------------------------------------------
231+
* Loose comparision is intentional, cause $time
232+
* is float and
233+
* (float)PHP_INT_MAX !== PHP_INT_MAX
229234
*/
230235
if ($time == PHP_INT_MAX) {
231236
return PHP_INT_MAX;

0 commit comments

Comments
 (0)