Skip to content

Instantly share code, notes, and snippets.

@georgringer
Last active April 4, 2022 05:06
Show Gist options
  • Save georgringer/80e26d6e1221627f2077c65c807e698b to your computer and use it in GitHub Desktop.
Save georgringer/80e26d6e1221627f2077c65c807e698b to your computer and use it in GitHub Desktop.
Getting the exception Symfony\Component\RateLimiter\Policy\SlidingWindow::getExpirationTime(): Return value must be of type int, float returned

About error SlidingWindow::getExpirationTime(): Return value must be of type int,

This gist should help you if you are getting the following exception in your TYPO3 website Symfony\Component\RateLimiter\Policy\SlidingWindow::getExpirationTime(): Return value must be of type int, float returned.

The following requirements must be set to be affected:

  • TYPO3 11.5
  • PHP 8.1. Read more about the relevant changes at php.watch
  • Package symfony/rate-limiter in version 5.4.7 (released 2022-04-02)
  • Deprecations notices are converted into exceptions

The bug in the symfony component has been discovered on 2022-04-03 and fixed on the same day. Thanks to everybody involved ❤!

Fixing it on your system

To fix the issue the following options are possible:

1. Downgrade the package

Use composer req symfony/rate-limiter:5.4.3 to downgrade to the version before.

2. Add current version as conflict

This method got the advantage that you will get automatically new versions once released.

"conflict": {
    "symfony/rate-limiter": "5.4.7"
}

3. Patch the package

Use the aweseome package cweagans/composer-patches and a patch file like

Index: Policy/SlidingWindow.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/Policy/SlidingWindow.php b/Policy/SlidingWindow.php
--- a/Policy/SlidingWindow.php
+++ b/Policy/SlidingWindow.php	(date 1648547298000)
@@ -76,7 +76,7 @@
      */
     public function getExpirationTime(): int
     {
-        return $this->windowEndAt + $this->intervalInSeconds - microtime(true);
+        return (int)($this->windowEndAt + $this->intervalInSeconds - microtime(true));
     }

     public function isExpired(): bool

Some personal take aways

  1. Open source is great! The bug has been identified by @sbuerk and @georgringer on a Sunday morning and the patch has been merged by @nicolas-grekas only a couple hours later!
  2. Automated tests work! The automated daily tests of TYPO3 discovered the code. Tests work!
  3. Always adopt your code to latest standards, use e.g. return types. It helps not only the IDE but if the code fails, you will be able to spot it

Thanks also to Studio Mitte, my employer who is sponsoring the work time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment