Review main Abandoned

91119[TASK] Avoid `not representable as an int, cast occurred ` PHP85 warning

Stefan Bürk CR 0 V 0 Easy +2 −2 updated 10/22/25, 12:38

Commit message

Float values not representable as int and cast to int intentionally
emits a PHP warning since PHP8.5 detected by unit and functional tests.

This change mitigates warnings similar to

    The float 1.4393998882452697E+19 is not representable as an int,
    cast occurred

The `@` suppress operator is used on the cast to mitigate this, albeit
looking weird and needs some time to get used to it.

Review

  • Code review CR 0
  • Verified V 0
    • core-ci +1 CI

Issues 1

Files 2

Review log 1519

  1. Stefan Bürk uploaded patch set 1 10/17/25, 08:36

  2. Georg Ringer commented on patch set 1 10/17/25, 08:56

    so why using a hexdec if we are using an integer only? why not generating a random int right away?
  3. Andreas Kienast commented on patch set 1 10/17/25, 08:57

    Why don't we use `(int)floor($float)`? This should mimic the previous behavior and does not fiddle with error reporting.
  4. core-ci voted on patch set 1 V +1 10/17/25, 08:57 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/86878

  5. Andreas Kienast commented on patch set 1 10/17/25, 09:00

    Reply

    Alright, just tested this with PHP 8.5: ``` php > var_dump(floor(1.4393998882452697E+19)); float(1.4393998882452697E+19) ``` What a weird handling...
  6. Stefan Bürk commented on patch set 1 10/17/25, 09:24

    Reply

    > floor(int|float $num): float Using floor() is not an option here, which would require a int or float value which would not work with a "string" and requring additional cast(s). Beside this, it returns a float so it would not avoid the issue with casting to int. I'd prefere the current solution, which is basically the same which Sebastian Bergman used in the one or other package and also others out there. Could find a better solution for this, but I'm open for it. What should we do ? @akienast@scripting-base.de
  7. Stefan Bürk rebased onto patch set 2 V +1 10/17/25, 09:25

  8. core-ci voted on patch set 2 V +1 10/17/25, 09:42 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/86882

  9. Stefan Bürk commented on patch set 2 10/17/25, 10:27

    Reply

    For `RecoveryCodes`: `hexdec()` returns the int reprecentation of the hex string, in case the value is to big it is returned as float, and I guess that was the reason why the `(int)` cast has been added in the first place. I would assume that we may change that here, either decreasing the hexstring length or using an other kind of "randomized integer" to mitigate the `hexdec() -> float -> int-cast` issue here, but I'm not really sure if there are impacts I do not see changing that. So far I understand the code this should be doable in some way. Maybe @ben@bnf.dev, @oliver.hader@typo3.org or @bo@cedev.de can have a look here for https://review.typo3.org/c/Packages/TYPO3.CMS/+/91119/2/typo3/sysext/core/Classes/Authentication/Mfa/Provider/RecoveryCodes.php#67 if that may be changed away from the hexstring/hexdec or at least reduced/lowered: ``` $number = @(int)hexdec($random->generateRandomHexString(16)); // We only want to work with positive integers if ($number < 0) { continue; } ```
  10. Stefan Bürk commented on patch set 2 10/17/25, 10:38

    Reply

    Reducing to `15` instead of `16` for `generateRandomHexString()` would return `int` calling `hexdec()` and the `issue` casting a to "big" float should go away without the need to suppress it. I'd suggest to lower that here to ``` $number = @(int)hexdec($random->generateRandomHexString(12)); ``` to be on the safe side. However, I wonder what happens if the method is called with `length: 200` and what kind of codes are generated in that case (or if a max length check needs to be added like the min length check).
  11. Stefan Bürk rebased onto patch set 3 V +1 10/17/25, 16:23

  12. core-ci voted on patch set 3 V +1 10/17/25, 16:32 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/86941

  13. Oliver Klee updated the commit message in patch set 4 V +1 10/17/25, 19:14

  14. core-ci voted on patch set 4 V +1 10/17/25, 19:24 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/86951

  15. Oliver Hader commented on patch set 4 10/20/25, 11:26

    Reply

    It would be possible to use `random_int(0,9)` directly instead of converting a 64-bit word back to integer. `PHP_INT_MAX` (`9223372036854775807`) is just a 63-bit integer.
  16. Oliver Hader commented on patch set 4 10/20/25, 11:59

    Reply

  17. Oliver Hader commented on patch set 4 10/21/25, 13:50

    Reply

    Done
  18. Oliver Klee commented on patch set 4 10/21/25, 14:33

  19. Stefan Bürk abandoned the change 10/22/25, 12:38

    resolved with dedicated changes in other ways. Not needed anymore.