3v4l.org

run code in 500+ PHP versions simultaneously
<?php function absint( $maybeint ): int { $abs = abs( (int) $maybeint ); /* * abs() can return a float when $maybeint is larger than PHP_INT_MAX. * When that happens, PHP 8.5+ emits a warning that the vale is not * representable as an int and a float value is returned. In this case, * the value is clamped to PHP_INT_MAX. */ if ( is_float( $abs ) ) { return PHP_INT_MAX; } return $abs; } $maybeints = array( 'zero' => 0, 'negative 1 int' => -1, 'positive 1 int' => 1, 'negative min int' => PHP_INT_MIN, 'negative min int minus 1' => PHP_INT_MIN - 1, 'negative min int times 2' => PHP_INT_MIN * 2, 'positive max int' => PHP_INT_MAX, 'positive max int plus 1' => PHP_INT_MAX + 1, 'positive max int times 2' => PHP_INT_MAX * 2, 'positive max int as string' => (string) PHP_INT_MAX, 'positive max int times 1000 as string' => (string) PHP_INT_MAX . '000', ); foreach ( $maybeints as $case => $maybeint ) { echo "# $case\n\n"; echo 'Input: '; var_dump( $maybeint ); echo 'Outut: '; var_dump( absint( $maybeint ) ); echo "\n"; }
Output for git.master, git.master_jit
# zero Input: int(0) Outut: int(0) # negative 1 int Input: int(-1) Outut: int(1) # positive 1 int Input: int(1) Outut: int(1) # negative min int Input: int(-9223372036854775808) Outut: int(9223372036854775807) # negative min int minus 1 Input: float(-9.223372036854776E+18) Outut: int(9223372036854775807) # negative min int times 2 Input: float(-1.8446744073709552E+19) Outut: Warning: The float -1.8446744073709552E+19 is not representable as an int, cast occurred in /in/LNMss on line 4 int(0) # positive max int Input: int(9223372036854775807) Outut: int(9223372036854775807) # positive max int plus 1 Input: float(9.223372036854776E+18) Outut: Warning: The float 9.223372036854776E+18 is not representable as an int, cast occurred in /in/LNMss on line 4 int(9223372036854775807) # positive max int times 2 Input: float(1.8446744073709552E+19) Outut: Warning: The float 1.8446744073709552E+19 is not representable as an int, cast occurred in /in/LNMss on line 4 int(0) # positive max int as string Input: string(19) "9223372036854775807" Outut: int(9223372036854775807) # positive max int times 1000 as string Input: string(22) "9223372036854775807000" Outut: int(9223372036854775807)

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
40.5 ms | 854 KiB | 4 Q