#48496 [Bgs->Opn]: String to numerical conversion
| From: | rquadling@php.net | Date: | Tue, 09 Jun 2009 09:11:39 +0000 |
| Subject: | #48496 [Bgs->Opn]: String to numerical conversion | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-2357@lists.php.net to get a copy of this message | ||
ID: 48496
Updated by: rquadling@php.net
Reported By: headden at karelia dot ru
-Status: Bogus
+Status: Open
Bug Type: Documentation problem
Operating System: Irrelevant
PHP Version: Irrelevant
-Assigned To:
+Assigned To: rquadling
Previous Comments:
------------------------------------------------------------------------
[2009-06-09 06:59:55] headden at karelia dot ru
> As 1234567890123 is larger than a 32bit integer, it is converted to a
float.
I understand what and why happens in described case. The bug is not in
PHP engine, but in documentation which does not describe this case.
According to documentation "1234567890123" will be treated as 'integer'
causing unpredictable truncation/overflow prior to evaluating +
operator.
I.e. the original phrase "The string will be evaluated as a float if it
contains any of the characters '.', 'e', or 'E'. Otherwise, it will be
evaluated as an integer." should be changed to something like this:
"If the string does not contain any of the characters '.', 'e', or
'E'
and implied numeric value fits into integer type limits, the string will
be evaluated as an integer. In all other cases it will be evaluated as a
float."
------------------------------------------------------------------------
[2009-06-08 14:55:26] rquadling@php.net
Sorry, but your problem does not imply a bug in PHP itself. For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions. Due to the volume
of reports we can not explain in detail here why your report is not
a bug. The support channels will be able to provide an explanation
for you.
Thank you for your interest in PHP.
------------------------------------------------------------------------
[2009-06-08 14:55:11] rquadling@php.net
As 1234567890123 is larger than a 32bit integer, it is converted to a
float.
Once in a float it is quite happily allowed to be incremented as you
are
using.
------------------------------------------------------------------------
[2009-06-08 14:31:10] headden at karelia dot ru
Description:
------------
http://www.php.net/manual/en/language.types.string.php
"The string will be evaluated as a float if it contains any of the
characters '.', 'e', or 'E'. Otherwise, it will be evaluated as an
integer."
this statement is wrong, consider the following code:
$a = 1 + "1234567890123";
var_dump($a); // outputs 'float(1234567890124)' on a 32-bit platform
this means that "1234567890123" was treated as 'float' although it does
not have any of '.', 'e' or 'E' characters.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=48496&edit=1