Bug #75664 [Opn->Nab]: sprintf %u results in 0 for numbers with more digits than PHP_INT_MAX

From: Date: Mon, 11 Dec 2017 15:25:09 +0000
Subject: Bug #75664 [Opn->Nab]: sprintf %u results in 0 for numbers with more digits than PHP_INT_MAX
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-213051@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75664&edit=1 ID: 75664 Updated by: cmb@php.net Reported by: erik at evanv dot nl Summary: sprintf %u results in 0 for numbers with more digits than PHP_INT_MAX -Status: Open +Status: Not a bug Type: Bug Package: Strings related Operating System: linux 4.14.4 PHP Version: 7.2.0 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: Actually, this boils down to (int) (PHP_INT_MAX*2) being undefined[1], so this is not a bug. [1] <http://www.php.net/manual/en/language.types.integer.php#language.types.integer.casting.from-float> Previous Comments: ------------------------------------------------------------------------ [2017-12-10 23:35:07] erik at evanv dot nl Description: ------------ Code speaks for itself. This can lead to data corruption. A decent solution would be to display unknown least significant digits as 0 just like %f. Alternative would be an ArithmeticError. Test script: --------------- php > $var = PHP_INT_MAX * 2; php > echo sprintf("%f", $var); 18446744073709551616.000000 php > echo sprintf("%u", $var); 0 Expected result: ---------------- 18446744073709551616 Actual result: -------------- 0 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75664&edit=1

« previous php.bugs (#213051) next »