Edit report at https://bugs.php.net/bug.php?id=65418&edit=1
ID: 65418 Comment by: cmbecker69 at gmx dot de Reported by: brucewlee at verizon dot net Summary: Neither is_numeric() nor intval() recognize '0b...' strings. Status: Open Type: Bug Package: Scripting Engine problem Operating System: Irrelevant PHP Version: 5.4.0 and later Block user comment: N Private report: N New Comment: This is a duplicate of <https://bugs.php.net/bug.php?id=64877> Previous Comments: ------------------------------------------------------------------------ [2013-08-08 05:31:27] yohg...@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-08 05:11:50] yohg...@php.net binary format was introduced from 5.4.0. ------------------------------------------------------------------------ [2013-08-08 04:36:33] 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. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=65418&edit=1