php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #64877 is_numeric() doesn't treat strings in binary notation as documented
Submitted: 2013-05-18 12:40 UTC Modified: 2015-07-26 17:35 UTC
Votes:5
Avg. Score:3.6 ± 0.8
Reproduced:5 of 5 (100.0%)
Same Version:1 (20.0%)
Same OS:4 (80.0%)
From: cmbecker69 at gmx dot de Assigned: cmb (profile)
Status: Closed Package: Variables related
PHP Version: 5.4.0 and later OS: any
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: cmbecker69 at gmx dot de
New email:
PHP Version: OS:

 

 [2013-05-18 12:40 UTC] 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)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-05-19 10:22 UTC] 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-08-18 03:43 UTC] yohgaki@php.net
-Type: Documentation Problem +Type: Bug -Package: Documentation problem +Package: Scripting Engine problem
 [2013-08-18 03:43 UTC] yohgaki@php.net
Related to
https://bugs.php.net/bug.php?id=65418
 [2013-08-18 03:46 UTC] yohgaki@php.net
-PHP Version: 5.4.15 +PHP Version: 5.4.0 and later
 [2013-08-18 03:46 UTC] 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 04:01 UTC] 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-10-31 16:08 UTC] daniele dot didomizio at eurac dot edu
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)
 [2013-10-31 16:43 UTC] cmbecker69 at gmx dot de
| This is bugged also for hex numbers:

The results are as expected according to the documentation.  Note,
that a hexadecimal number is only reported as being numeric, if it
is in hexadecimal string notation (i.e. starting with 0x).  The first
example is correctly reported as being numeric, because the "e" is 
recognized as starting the exponential part of the number.
 [2013-10-31 16:49 UTC] nikic@php.net
Related discussion for is_numeric_string: http://markmail.org/message/ax2drcb6dolr5agl. General consensus is that we would rather remove hex support than add support for binary and octal.
 [2013-10-31 17:13 UTC] cmbecker69 at gmx dot de
-Type: Bug +Type: Documentation Problem -Package: Scripting Engine problem +Package: Documentation problem
 [2013-10-31 17:13 UTC] cmbecker69 at gmx dot de
| General consensus is that we would rather remove hex 
| support than add support for binary and octal.

Then it is a documentation problem.
 [2015-07-26 17:34 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=337240
Log: fixed documentation wrt. strings in non-decimal notation (fixes #64877)
 [2015-07-26 17:35 UTC] cmb@php.net
-Status: Open +Status: Closed -Package: Documentation problem +Package: Variables related -Assigned To: +Assigned To: cmb
 [2015-07-26 17:35 UTC] cmb@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 22 20:01:31 2024 UTC