php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65418 Neither is_numeric() nor intval() recognize '0b...' strings.
Submitted: 2013-08-08 04:36 UTC Modified: 2013-08-18 03:47 UTC
From: brucewlee at verizon dot net Assigned:
Status: Duplicate Package: Scripting Engine problem
PHP Version: 5.4.0 and later OS: Irrelevant
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: brucewlee at verizon dot net
New email:
PHP Version: OS:

 

 [2013-08-08 04:36 UTC] brucewlee at verizon dot net
Description:
------------
Neither is_numeric() nor intval() recognize '0b...' strings. 

Test script:
---------------
Code:
$as = array("0x10", "16", "020", "0b10000");
foreach($as as $v) {
	echo "The function is_numeric('" . $v . "') returns ";
	if (is_numeric($v)) { echo("true"); } else { echo("false"); };
	echo ".<br>";
}

Output:
The function is_numeric('0x10') returns true.
The function is_numeric('16') returns true.
The function is_numeric('020') returns true.
The function is_numeric('0b10000') returns false.

Code:
$as = array(["0x10", 16], ["16", 10], ["020", 8], ["0b10000", 2]);
foreach($as as $v) {
	echo "The function intval('" . $v[0] . "', " . $v[1] . ") returns " . intval($v[0], $v[1]) . ".<br>";
		}
Output:
The function intval('0x10', 16) returns 16.
The function intval('16', 10) returns 16.
The function intval('020', 8) returns 16.
The function intval('0b10000', 2) returns 0.



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-08-08 05:11 UTC] yohgaki@php.net
-Operating System: Windows 7 +Operating System: Irrelevant -PHP Version: 5.5.1 +PHP Version: 5.4.0 and later
 [2013-08-08 05:11 UTC] yohgaki@php.net
binary format was introduced from 5.4.0.
 [2013-08-08 05:31 UTC] yohgaki@php.net
-Package: Strings related +Package: Scripting Engine problem
 [2013-08-08 05:31 UTC] yohgaki@php.net
This is actually a scripting engine problem. Both is_numeric() and intval() end 
up calling function that defined in Zend/zend_operators.c. Responsive functions 
are not treat binary strings as integer string.

is_numeric() calls

static inline zend_uchar is_numeric_string_ex(const char *str, int length, long 
*lval, double *dval, int allow_errors, int *oflow_info)


inval() calls

ZEND_API void convert_to_long_base(zval *op, int base) /* {{{ */
....
		case IS_STRING:
			{
				char *strval = Z_STRVAL_P(op);

				Z_LVAL_P(op) = strtol(strval, NULL, base);
				STR_FREE(strval);
			}
			break;
 [2013-08-10 17:15 UTC] cmbecker69 at gmx dot de
This is a duplicate of <https://bugs.php.net/bug.php?id=64877>
 [2013-08-13 09:06 UTC] laruence@php.net
-Status: Open +Status: Duplicate
 [2013-08-13 09:06 UTC] laruence@php.net
dup to #64877
 [2013-08-18 03:47 UTC] yohgaki@php.net
It would be better to cross referenced. I added link to this bug.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC