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 #181420 is a reply to message #181417] Wed, 15 May 2013 20:42 Go to previous messageGo to previous message
Christoph Becker is currently offline  Christoph Becker
Messages: 91
Registered: June 2012
Karma:
Member
Thomas 'PointedEars' Lahn wrote:
> Christoph Becker wrote:
>
>> Thomas 'PointedEars' Lahn wrote:
>>> 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].
>>
>> ACK. However, the usefulness of is_numeric() returning true for strings
>> in binary notation is somewhat doubtful, as there is no simple way to
>> actually convert such strings to a number:
>>
>>>> > (int) '0b1010'
>> 0
>>>> > intval('0b1010')
>> 0
>>>> > intval('0b1010', 2)
>> 0
>>>> > 0 + '0b1010'
>> 0
>>
>> So the issue *might* as well be regarded as documentation bug.
>
> ISTM to be strong indication that it is an implementation bug, where
> the bug would be that the conversion from string to int is incomplete:
>
> $ php -r 'var_dump(+"0x2A");'
> int(42)
>
> (as expected)
>
> $ php -r 'var_dump(+"010");'
> int(10)
>
> (expected: 8)

Interestingly the type cast to int has another result:

$ php -r 'var_dump((int) "0x2A");'
int(0)

In bug report #52950[1] the latter behavior is reported as expected.
IMO the former behavior is more useful and consistent. Anyway, the
explicit type cast and the implicit type juggling should have the same
result.

> A possibility for conversion is:
>
> $ php -r 'var_dump(eval("return " . "0b1110" . ";"));'
> int(14)

Ugly, but effective.

>> BTW: I can confirm the same behavior in PHP 5.2.17 (Windows VC6 build).
>
> Bogus because binary numeric literals were introduced in PHP 5.4.

I wasn't aware of that. Thanks for pointing it out.

[1] <https://bugs.php.net/bug.php?id=52950>

--
Christoph M. Becker
[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: Wed Nov 27 02:22:49 GMT 2024

Total time taken to generate the page: 0.04372 seconds