Bug #61220 [Com]: is_numeric returns FALSE for chr(0) and CHR(1) that are BIT, so NUMERIC.
| From: | dosergio at ig dot com dot br | Date: | Thu, 01 Mar 2012 15:02:02 +0000 |
| Subject: | Bug #61220 [Com]: is_numeric returns FALSE for chr(0) and CHR(1) that are BIT, so NUMERIC. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-167964@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=61220&edit=1
ID: 61220
Comment by: dosergio at ig dot com dot br
Reported by: dosergio at ig dot com dot br
Summary: is_numeric returns FALSE for chr(0) and CHR(1) that
are BIT, so NUMERIC.
Status: Open
Type: Bug
Package: *General Issues
Operating System: ALL
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
I also tested chr(0) and chr(1) with is_boolean and of course the function says it is not.
I think is_numeric and is_boolean should be revised to include 0, 1, chr(0) and chr(1) as valid
numeric and valid booleans.
Previous Comments:
------------------------------------------------------------------------
[2012-03-01 14:13:56] dosergio at ig dot com dot br
if( is_numeric( chr(0)) && is_numeric(chr(1)) ) # <-- changed to &&
echo "is_numeric is great!";
else
echo "is_numeric might be a little buggy";
------------------------------------------------------------------------
[2012-03-01 14:12:13] dosergio at ig dot com dot br
Description:
------------
I think that is_numeric should return TRUE if you pass chr(0) or chr(1) to it because this chars are
stored in database as BITs, that are numeric in the binary context. Would php adopt it ?
I had to use a strange conditional because of this supposed "bug":
[code]
if( is_numeric($myvar) || ord($myvar) < 2) {
# to check char 0 or 1 that are BITS, binary numeric.
}
[/code]
Test script:
---------------
if( is_numeric( chr(0)) || is_numeric(chr(1)) )
echo "is_numeric is great!";
else
echo "is_numeric might be a little buggy";
Expected result:
----------------
is_numeric shoud recognize chr(0) and chr(1) as numeric, as they are chars for bit information.
Actual result:
--------------
is_numeric says chr(0) and chr(1) are both NOT numeric.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=61220&edit=1