#26349 [Opn->Bgs]: is_numeric() returns false for strings with more than 308 characters

From: Date: Fri, 21 Nov 2003 20:10:54 +0000
Subject: #26349 [Opn->Bgs]: is_numeric() returns false for strings with more than 308 characters
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-50821@lists.php.net to get a copy of this message
 ID:               26349
 Updated by:       jay@php.net
 Reported By:      kouber at saparev dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Math related
 Operating System: Win 2000 NT
 PHP Version:      4.3.4
 New Comment:

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 


Previous Comments:
------------------------------------------------------------------------

[2003-11-21 09:22:31] 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)


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=26349&edit=1


Thread (3 messages)

« previous php.bugs (#50821) next »