Bug #64877 [Com]: is_numeric() doesn't treat strings in binary notation as documented

From: Date: Thu, 31 Oct 2013 16:08:46 +0000
Subject: Bug #64877 [Com]: is_numeric() doesn't treat strings in binary notation as documented
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-182521@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=64877&edit=1 ID: 64877 Comment by: daniele dot didomizio at eurac dot edu Reported by: cmbecker69 at gmx dot de Summary: is_numeric() doesn't treat strings in binary notation as documented Status: Open Type: Bug Package: Scripting Engine problem Operating System: any PHP Version: 5.4.0 and later Block user comment: N Private report: N New Comment: This is bugged also for hex numbers: print "526e948280122 " .(is_numeric("526e948280122") ? "numeric" : "not numeric"). PHP_EOL; print "526a948280122 ". (is_numeric("526a948280122") ? "numeric" : "not numeric"). PHP_EOL; print "0x526a948280122 ". (is_numeric("0x526a948280122") ? "numeric" : "not numeric"). PHP_EOL; print "526f948280122 ". (is_numeric("526f948280122") ? "numeric" : "not numeric"). PHP_EOL; output is: 526e948280122 numeric 526a948280122 not numeric 0x526a948280122 numeric 526f948280122 not numeric tested with versions 5.5.4-1 and 5.4.4 (Debian version 5.4.4-14+deb7u5) Previous Comments: ------------------------------------------------------------------------ [2013-08-18 04:01:08] yohgaki@php.net > is_numeric()/intval() (many others) were not taken into account new format. is_numeric()/intval() (may be others) were not taken into account new format. ------------------------------------------------------------------------ [2013-08-18 03:46:48] yohgaki@php.net This problem was introduced when binary format integer was supported. is_numeric()/intval() (many others) were not taken into account new format. ------------------------------------------------------------------------ [2013-08-18 03:43:45] yohgaki@php.net Related to https://bugs.php.net/bug.php?id=65418 ------------------------------------------------------------------------ [2013-05-19 10:22:43] ramon dot ornela at gmail dot com This is a bug, already that the is_numeric supported octal e hexadecimal, should add support to binary annotation too. ------------------------------------------------------------------------ [2013-05-18 12:40:46] cmbecker69 at gmx dot de Description: ------------ In PHP 5.4.15 the definition of is_numeric() is in ext/standard/type.c (line 300ff)[1]. The relevant function to do the check for arguments of type string is is_numeric_string_ex() in Zend/zend_operators.h (line 109ff)[2]. Apparently special support for strings in binary as well as octal notation is missing; only strings in decimal and hexadecimal notation are recognized as such (strings in octal notation are treated as being decimal). I have filed this issue as documentation problem, but it might be considered an implementation bug. [1] <http://lxr.php.net/xref/PHP_5_4/ext/standard/type.c> [2] <http://lxr.php.net/xref/PHP_5_4/Zend/zend_operators.h> Test script: --------------- var_dump(is_numeric('0b1')); Expected result: ---------------- bool(true) Actual result: -------------- bool(false) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=64877&edit=1

« previous php.bugs (#182521) next »