php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26349 is_numeric() returns false for strings with more than 308 characters
Submitted: 2003-11-21 09:22 UTC Modified: 2003-11-24 02:54 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: kouber at saparev dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: 4.3.4 OS: Win 2000 NT
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
18 - 7 = ?
Subscribe to this entry?

 
 [2003-11-21 09:22 UTC] kouber at saparev dot com
Description:
------------
is_numeric() always returns false for strings with more than 308 characters, even if all of them are digits.

308 = 255 + 63 = 2^8-1 + 2^6-1

Reproduce code:
---------------
<?
$s = str_repeat('6', 309);

var_dump($s);

var_dump(is_numeric($s));
?>

Expected result:
----------------
string(309) "666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666"
bool(true)

Actual result:
--------------
string(309) "666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666"
bool(false)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-11-21 15:10 UTC] jay@php.net
Please see the note on the maximum value of floats at 
 
http://www.php.net/manual/en/language.types.float.php 
 
When is_numeric() checks a string, it tries to convert the 
string to a long, then a double. Anything greater than 
approximately 1.8e308 is too large for a double, so it 
becomes infinity. Try a var_dump() on the value and you'll 
see what I mean. (This behaviour is platform-dependent, of 
course.) 
 
J 
 [2003-11-24 02:54 UTC] kouber at saparev dot com
I see.

I just didn't saw in the documentation of that function such an explanation.

http://www.php.net/is-numeric

I'll add a user comment, but maybe it should be better to add this in the manual itself, someday... :)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 14:01:31 2024 UTC