diff --git a/src/Header/SetCookie.php b/src/Header/SetCookie.php index 1c946c2fb9..51bbb64512 100644 --- a/src/Header/SetCookie.php +++ b/src/Header/SetCookie.php @@ -354,15 +354,24 @@ public function setExpires($expires) return $this; } + $tsExpires = $expires; if (is_string($expires)) { - $expires = strtotime($expires); + $tsExpires = strtotime($expires); + + // if $tsExpires is invalid and PHP is compiled as 32bit. Check if it fail reason is the 2038 bug + if (!is_int($tsExpires) && PHP_INT_SIZE === 4) { + $dateTime = new \DateTime($expires); + if ( $dateTime->format('Y') > 2038) { + $tsExpires = PHP_INT_MAX; + } + } } - if (!is_int($expires) || $expires < 0) { + if (!is_int($tsExpires) || $tsExpires < 0) { throw new Exception\InvalidArgumentException('Invalid expires time specified'); } - $this->expires = $expires; + $this->expires = $tsExpires; return $this; } diff --git a/test/Header/SetCookieTest.php b/test/Header/SetCookieTest.php index d958cd587e..27c6f64e62 100644 --- a/test/Header/SetCookieTest.php +++ b/test/Header/SetCookieTest.php @@ -254,6 +254,19 @@ public function testSetCookieSetExpiresWithUnixEpochString() $this->assertSame($target, $setCookieHeader->getFieldValue()); } + /** + * Check that setCookie does not fail when an expiry date which is bigger then 2038 is supplied (effect only 32bit systems) + */ + public function testSetCookieSetExpiresWithStringDateBiggerThen2038() + { + if ( PHP_INT_SIZE !== 4 ) { + $this->markTestSkipped('Testing set cookie expiry which is over 2038 is only relevant on 32bit systems'); + return; + } + $setCookieHeader = new SetCookie('myname', 'myvalue', 'Thu, 01-Jan-2040 00:00:00 GMT'); + $this->assertSame(2147483647, $setCookieHeader->getExpires(true)); + } + public function testIsValidForRequestSubdomainMatch() { $setCookieHeader = new SetCookie(