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

hexdec() Warns When The Result Loses Precision

hexdec(), bindec(), octdec() and base_convert() return a float when the converted number is too large to fit in a PHP integer. Until PHP 8.6, this silently lost precision, since a 64-bit float cannot represent every integer up to the represented magnitude exactly. In PHP 8.6, these functions raise a notice when the returned value cannot precisely represent the input number.

PHP code

<?php

var_dump(hexdec('FFFFFFFFFFFFFFFFFF'));

?>

Before

float(4.722366482869645E+21)

After

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

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

PHP version change

This behavior changed in 8.6.

See Also

Error Messages

Extension

© 2023-2026, Damien Seguy - Exakat