php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #48496 String to numerical conversion
Submitted: 2009-06-08 14:31 UTC Modified: 2009-06-09 09:33 UTC
From: headden at karelia dot ru Assigned: rquadling (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: Irrelevant
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: headden at karelia dot ru
New email:
PHP Version: OS:

 

 [2009-06-08 14:31 UTC] 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.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-08 14:55 UTC] 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:55 UTC] 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-09 06:59 UTC] 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-09 09:33 UTC] rquadling@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

"If the string does not contain any of the characters '.', 'e', or 'E' 
and implied numeric value fits into integer type limits (as defined by 
PHP_INT_MAX), the string will be evaluated as an integer. In all other 
cases it will be evaluated as a float."
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 08:00:02 2026 UTC