Req #37993 [Opn->Wfx]: integer type conversion behavior is inconsistent

From: Date: Fri, 09 Jan 2015 00:28:48 +0000
Subject: Req #37993 [Opn->Wfx]: integer type conversion behavior is inconsistent
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-189802@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=37993&edit=1 ID: 37993 Updated by: ajf@php.net Reported by: shailesh_bavadekar at yahoo dot com Summary: integer type conversion behavior is inconsistent -Status: Open +Status: Wont fix Type: Feature/Change Request -Package: Feature/Change Request +Package: *General Issues Operating System: all PHP Version: 5.1.4 Block user comment: N Private report: N New Comment: If someone asks for an integer, they should get an integer. Converting to float when someone asks for an *integer* would be incredibly counter-intuitive. Big Integer Support (http://wiki.php.net/rfc) would "resolve" this the way you'd like, though. Previous Comments: ------------------------------------------------------------------------ [2006-07-03 02:37:53] shailesh_bavadekar at yahoo dot com Description: ------------ When an integer operand value exceeds 2^32 the php runtime automatically converts it into float. This is completely transparent to the applications dealing with integer arithmetic. It allows PHP applications to handle integers upto 2^53. (Larger values don't work correctly due to precision limits of 64 bit floating point format). However things are not so clear when numeric values are initially expressed as strings (e.g. read from a file or network). e.g. consider following code - <?php $i1 = 4294967296; $i2 = 2147483647 * 2 + 2; $i3 = (integer) 4294967296; $i4 = (integer) "4294967296"; echo $i1 . "\n"; // prints 4294967296 echo $i2 . "\n"; // prints 4294967296 echo $i3 . "\n"; // prints 0! echo $i4 . "\n"; // prints 2147483647!! ?> Proposed fix: The "automatic conversion to float" rule should be uniformly applied in all these cases even if the program wants to explicitly cast to integer. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=37993&edit=1

« previous php.bugs (#189802) next »