CKTIS / PHP
PHP_INT_MAX / PHP_INT_MIN
The pair PHP_INT_MAX / PHP_INT_MIN names the largest and smallest native signed integers, with limits dependent on the build’s integer width.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
$overflow = PHP_INT_MAX + 1;The pair PHP_INT_MAX / PHP_INT_MIN names the largest and smallest native signed integers, with limits dependent on the build’s integer width. PHP_INT_MIN equals -PHP_INT_MAX - 1. Ordinary addition or subtraction past either bound promotes the result to float, which cannot represent every large integer exactly. The example checks types and limits without assuming a 64-bit machine.
$above = PHP_INT_MAX + 1;
$below = PHP_INT_MIN - 1;
echo json_encode([
PHP_INT_MIN === -PHP_INT_MAX - 1,
get_debug_type(PHP_INT_MAX), get_debug_type(PHP_INT_MIN),
get_debug_type($above), get_debug_type($below)
]);
[true,"int","int","float","float"]
Examples
<?php
$above = PHP_INT_MAX + 1;
$below = PHP_INT_MIN - 1;
echo json_encode([
PHP_INT_MIN === -PHP_INT_MAX - 1,
get_debug_type(PHP_INT_MAX), get_debug_type(PHP_INT_MIN),
get_debug_type($above), get_debug_type($below)
]);
Result
[true,"int","int","float","float"]