is_numeric_string causes function inconsistency
| From: | Matt W | Date: | Sun, 06 Aug 2006 08:15:44 +0000 |
| Subject: | is_numeric_string causes function inconsistency | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-25207@lists.php.net to get a copy of this message | ||
Hi all,
Since I've been looking at is_numeric_[string|unicode], I found a weird
thing it causes; probably doesn't make sense to users; bug? Look:
abs(-1e500) // float(INF)
abs('-1e500') // int(1) WRONG
abs('-1e100') // float(1.0E+100)
is_finite(1e500) // bool(false)
is_finite('1e500') // bool(true) WRONG
is_finite('1e100') // bool(true)
is_numeric(1e500) // bool(true)
is_numeric('1e500') // bool(false) WRONG
is_numeric('1e100') // bool(true)
1e500 + 123 // float(INF)
'1e500' + 123 // int(124) WRONG
You get the idea. That's because is_numeric_string() *ignores* the value
from zend_strtod() if errno==ERANGE. I don't think that's right, and it
doesn't happen when convert_to_double() uses zend_strtod():
number_format(1e500) // string(3) "inf"
number_format('1e500') // string(3) "inf" RIGHT
Just wondering if others think is_numeric_string() should be changed in that
respect? I was going to rewrite the function to improve/optimize it (and
submit it of course), so I can easily change its behavior while I'm at it...
Also, is this the desired behavior of array_count_values() (manual doesn't
say; it also uses is_numeric...)?
print_r(array_count_values(array(1, ' 1', ' 1 ')))
Array
(
[1] => 2
[ 1 ] => 1
)
Matt