FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » bug in is_numeric
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: bug in is_numeric [message #181445 is a reply to message #181413] Thu, 16 May 2013 22:16 Go to previous messageGo to previous message
SwissCheese is currently offline  SwissCheese
Messages: 17
Registered: December 2012
Karma:
Junior Member
On 05/15/2013 02:49 PM, Thomas 'PointedEars' Lahn wrote:
> Christoph Becker wrote:
>
>> Thomas 'PointedEars' Lahn wrote:
>>> SwissCheese wrote:
>>>> norman@amd64x2:~$ php -a
>>>> Interactive shell
>>>>
>>>> php > $a = 'x';
>>>> php > if(is_numeric($a)) { echo 'okay'; } else { echo 'not okay'; }
>>>> not okay
>>>> php > $a = '11';
>>>> php > if(is_numeric($a)) { echo 'okay'; } else { echo 'not okay'; }
>>>> okay
>>>> php > $a = 'x11.11c';
>>>> php > if(is_numeric($a)) { echo 'okay'; } else { echo 'not okay'; }
>>>> not okay
>>>> php > $a = '0x1111c';
>>>> php > if(is_numeric($a)) { echo 'okay'; } else { echo 'not okay'; }
>>>> okay
>>>>
>>>> As per http://us3.php.net/manual/en/function.is-numeric.php :
>>>>
>>>> "Hexadecimal (e.g. 0xf4c3b00c), Binary (e.g. 0b10100111001), Octal (e.g.
>>>> 0777) notation is allowed too but only without sign, decimal and
>>>> exponential part."
>>>
>>> But AISB, the implementation is contradicting the documentation (or vice-
>>> versa) because the a string argument containing the binary format causes
>>> is_numeric() to return FALSE in PHP 5.4.4 and PHP 5.4.14 (when according
>
> 5.4.15(-1; Debian), not .14
>
>>> to the above it should have returned TRUE).
>>
>> I can confirm issues with is_numeric() wrt. strings in binary notation
>> in PHP 5.4.7:
>>
>>>> > is_numeric('0b1010')
>> false
>>>> > is_numeric(0b1010)
>> true
>
> ACK. However, it is unsurprising to me that the latter would return TRUE
> because there the literal is parsed into an “int” value *before* it is
> passed to is_numeric(), the equivalent of is_numeric(10).
>
> I would rather the former bug was an implementation bug instead of a
> documentation bug, because such a function should either work for all
> supported numeric representations of the programming language, or there
> should be a parameter specifying which representations are supported for the
> specific call [like ECMAScripts parseInt(number : String, base : Number) :
> Number].
>
>
> PointedEars
>

Thomas,

Looking into the source (PHP) there is no code to support binary
strings of the type '0b1010101'. The code for hexadecimal is there however.

php > $tests =
array("42",1337,"0xf4c3b00c","x11.11c","0x11.11c","0x1111c","0b1010 ","0b10101",
" 101010101010101010101010101010101010101010101010101010101010101010101010101 01010101010 ",
"0700");
php > foreach ($tests as $a) { if(is_numeric($a)) { echo "$a is numeric
".var_dump(is_numeric($a)).PHP_EOL; } else { echo "$a is not
numeric".var_dump(is_numeric($a)).PHP_EOL; } }
bool(true)
42 is numeric
bool(true)
1337 is numeric
bool(true)
0xf4c3b00c is numeric
bool(false)
x11.11c is not numeric
bool(false)
0x11.11c is not numeric
bool(true)
0x1111c is numeric
bool(false)
0b1010 is not numeric
bool(false)
0b10101 is not numeric
bool(true)
101010101010101010101010101010101010101010101010101010101010101010101010101 01010101010
is numeric
bool(true)
0700 is numeric


--
Norman
Registered Linux user #461062
-Have you been to www.php.net yet?-
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: problem encrypting data (AES_ENCRYPT/AES_DECRYPT)
Next Topic: Debian: php fast-cgi along with mod_php
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 26 23:13:56 GMT 2024

Total time taken to generate the page: 0.06631 seconds