3v4l.org

run code in 500+ PHP versions simultaneously
<?php function absint( $maybeint ): int { return abs( (int) $maybeint ); } function safe_absint( $maybeint ): int { $maybeint = (int) $maybeint; // Avoid PHP fatal error where we might return a float instead of an int if ( PHP_INT_MIN === $maybeint ) { return PHP_INT_MAX; } return abs( $maybeint ); } $stuff = '-99999999999999999999'; var_dump( safe_absint( $stuff ) ); var_dump( absint( $stuff ) );
Output for 8.2.31 - 8.2.33, 8.3.0 - 8.3.33, 8.4.1 - 8.4.24, 8.5.2 - 8.5.9
int(9223372036854775807) Fatal error: Uncaught TypeError: absint(): Return value must be of type int, float returned in /in/6JIR0:4 Stack trace: #0 /in/6JIR0(22): absint('-99999999999999...') #1 {main} thrown in /in/6JIR0 on line 4
Process exited with code 255.
Output for 8.5.0 - 8.5.1
Warning: The float-string "-99999999999999999999" is not representable as an int, cast occurred in /in/6JIR0 on line 8 int(9223372036854775807) Warning: The float-string "-99999999999999999999" is not representable as an int, cast occurred in /in/6JIR0 on line 4 Fatal error: Uncaught TypeError: absint(): Return value must be of type int, float returned in /in/6JIR0:4 Stack trace: #0 /in/6JIR0(22): absint('-99999999999999...') #1 {main} thrown in /in/6JIR0 on line 4
Process exited with code 255.

preferences:
44.15 ms | 796 KiB | 4 Q