3v4l.org

run code in 500+ PHP versions simultaneously
<?php function absint( $maybeint ): int { if ( ! is_numeric( $maybeint ) ) { return 0; } if ( is_float( $maybeint ) ) { $value = abs( $maybeint ); if ( $value >= PHP_INT_MAX ) { return PHP_INT_MAX; } else { return (int) $value; } } // Convert numeric-string to int. $value = (int) $maybeint; // Special case for the one integer which cannot survive abs(). if ( PHP_INT_MIN === $value ) { return PHP_INT_MAX; } return abs( $value ); } $maybeints = array( 'positive max int times 2' => PHP_INT_MAX * 2, 'zero' => 0, 'string' => 'foo', '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 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 'Output: '; var_dump( absint( $maybeint ) ); echo "\n"; }
Output for git.master_jit, rfc.property-hooks, git.master
# positive max int times 2 Input: float(1.8446744073709552E+19) Output: int(9223372036854775807) # zero Input: int(0) Output: int(0) # string Input: string(3) "foo" Output: int(0) # negative 1 int Input: int(-1) Output: int(1) # positive 1 int Input: int(1) Output: int(1) # negative min int Input: int(-9223372036854775808) Output: int(9223372036854775807) # negative min int minus 1 Input: float(-9.223372036854776E+18) Output: int(9223372036854775807) # negative min int times 2 Input: float(-1.8446744073709552E+19) Output: int(9223372036854775807) # positive max int Input: int(9223372036854775807) Output: int(9223372036854775807) # positive max int plus 1 Input: float(9.223372036854776E+18) Output: int(9223372036854775807) # positive max int as string Input: string(19) "9223372036854775807" Output: int(9223372036854775807) # positive max int times 1000 as string Input: string(22) "9223372036854775807000" Output: 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:
79.62 ms | 3086 KiB | 4 Q