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.5.0 - 8.5.9
Warning: The float -1.0E+20 is not representable as an int, cast occurred in /in/ZXDUu on line 8 int(7766279631452241920) Warning: The float -1.0E+20 is not representable as an int, cast occurred in /in/ZXDUu on line 4 int(7766279631452241920)
Output for 8.2.31 - 8.2.33, 8.3.0 - 8.3.33, 8.4.1 - 8.4.24
int(7766279631452241920) int(7766279631452241920)

preferences:
47.32 ms | 775 KiB | 4 Q