Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Base Conversion Functions Warn When Precision Is Lost

bindec(), octdec(), hexdec() and base_convert() all share the same internal conversion routine, which accumulates the result in a platform integer for as long as it fits, then switches to a float once the value would overflow. That switch already happened silently before PHP 8.6: a double only has 53 bits of mantissa, so digits beyond that are rounded away without any indication. In PHP 8.6, the switch to float now also emits an E_NOTICE, while the returned value is unchanged.

PHP code

<?php

var_dump(hexdec('FFFFFFFFFFFFFFFF'));

?>

Before

float(1.8446744073709552E+19)

After

PHP Notice:  Input number is larger than PHP_INT_MAX, precision has been lost in conversion in /codes/baseConversionPrecisionLossNotice.php on line 3

Notice: Input number is larger than PHP_INT_MAX, precision has been lost in conversion in /codes/baseConversionPrecisionLossNotice.php on line 3
float(1.8446744073709552E+19)

PHP version change

This behavior changed in 8.6.

See Also

Error Messages

Extension

© 2023-2026, Damien Seguy - Exakat