operators might accidentally let a float * through. * * @param int|float $number The number we want to convert to an int * @param bool $fail_open Set to true to not throw an exception * * @return float|int * @psalm-suppress InvalidReturnType * * @throws TypeError */ function RandomCompat_intval($number, $fail_open = false) { if (is_int($number) || is_float($number)) { $number += 0; } elseif (is_numeric($number)) { /** @psalm-suppress InvalidOperand */ $number += 0; } /** @var int|float $number */ if ( is_float($number) && $number > ~PHP_INT_MAX && $number < PHP_INT_MAX ) { $number = (int) $number; } if (is_int($number)) { return (int) $number; } elseif (!$fail_open) { throw new TypeError( 'Expected an integer.' ); } return $number; } }