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 #181436 is a reply to message #181433] Thu, 16 May 2013 04:09 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 5/15/2013 8:57 PM, SwissCheese wrote:
> On 05/14/2013 11:01 PM, Jerry Stuckle wrote:
>> On 5/14/2013 9:43 PM, SwissCheese wrote:
>>> On 05/14/2013 09:41 AM, Richard Yates wrote:
>>>> On Mon, 13 May 2013 15:15:06 +0100, fred <email(at)address(dot)com> wrote:
>>>>
>>>> > In article <kmqs3c$e3s$1(at)dont-email(dot)me>, jstucklex(at)attglobal(dot)net
>>>> > says...
>>>> >> As others have shown, is_numeric() returns false in several versions
>>>> >> of PHP.
>>>> >>
>>>> >
>>>> > I have just typed in an exact copy of the test in my message of
>>>> > 02:58pm
>>>> > When you have run that on an apache PHP installation of the same
>>>> > version
>>>> > PHP as I listed (5.3.6) under windows7-64 bit - get back to me.
>>>> >
>>>> > Otherwise I'm done repeating myself.
>>>> >
>>>>
>>>> <?php
>>>> $a = 'x11.11c';
>>>> if(is_numeric($a)) { echo 'oops - a problem'; } else { echo 'okay'; }
>>>> ?>
>>>>
>>>> Prints 'okay'
>>>>
>>>> Windows 7 Home Premium 64 bit, PHP5.3.4, Apache2.2.17, (WAMP)
>>>>
>>>
>>> That's backwards... you want:
>>>
>>> $a = 'x11.11c';
>>> if(is_numeric($a)) { echo 'ok'; } else { echo 'not okay'; }
>>>
>>> Sorry, hit send too quick!
>>>
>>
>> No, Richard had it correct. The if statement returns false, which is
>> 'ok'. Your code would return 'not ok' - which is incorrect.
>>
>
> If $a ('x11.11c') is numeric then it would return 'ok' but it is not so
> it returns 'not ok'. 'x11.11c' is not hexadecimal, it lacks the leading
> '0' and contains a decimal/period.
>

'ok' is correct in this instance. is_numeric() should NOT return a
numeric value; if it did, that would be incorrect.

You are confusing 'not numeric' with 'not ok'. The first would return
whether the value is numeric or not. The second returns whether the
function returns the correct value or not.

The correct value is that the parameter is NOT a valid numeric value, so
'ok' (the function worked correctly) is the correct response.

> php > $tests =
> array("42",1337,"0xf4c3b00c","x11.11c","0x11.11c","0x1111c","0b1010 ",
> " 101010101010101010101010101010101010101010101010101010101010101010101010101 01010101010 ");
>
> php > foreach ($tests as $a) { if(is_numeric($a)) { echo "$a is
> numeric".PHP_EOL; } else { echo "$a is not numeric".PHP_EOL; } }
> 42 is numeric
> 1337 is numeric
> 0xf4c3b00c is numeric
> x11.11c is not numeric
> 0x11.11c is not numeric
> 0x1111c is numeric
> 0b1010 is not numeric
> 101010101010101010101010101010101010101010101010101010101010101010101010101 01010101010
> is numeric
>
>
> From what I can tell from the source code (of PHP) there is no code
> to handle binary strings as explained in the function definition at
> php.net. But I guess by definition it can only be 0's and 1's as seen
> above.
>
>
>

Binary strings are a completely different problem introduces by the
troll 'Pointed Head' which has nothing to do with the OP's problem. But
then 'Pointed Head' is notorious (in several newsgroups) for hijacking
threads for his own purpose.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[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: Thu Apr 03 06:34:31 GMT 2025

Total time taken to generate the page: 0.05726 seconds