Integer Becomes Negative

<?php

$a = PHP_INT_MAX;
$b = $a + 1;
$c = (int) $b;
$d = intval($b);

var_dump($b < 0);
var_dump($c < 0);
var_dump($d < 0);

$a is the largest integer in PHP. So, $b, which is one bigger than $a, is actually a float, which is bigger and still positive. When casting the float to an integer, the integer is turned into a negative number by overflowing.

See Also

PHP Features

Last updated: 14 July 2026