Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » PHP
  • » [PHP-DEV] Re: is_int/is_numeric possible bug [RSS Feed]

#1 Nov. 29, 2005 16:28:39

Ron K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Re: is_int/is_numeric possible bug


Just out of curiosity, to which versions does this apply?

Ron


"Gareth Ardron" <> schreef in bericht

> Hi.
>
> Think I've just stumbled upon a possible bug with is_int.
>
> if you've got the following code:
>
> <form action='1.php' method='post'>
> <input type='text' name='days'>
> <input type='submit' name='submit' value='submit'>
> </form>
> <?php
> if (!is_int($_REQUEST) || $_REQUEST < 0) {
> $_REQUEST = 10;
> }
> print "<br>days::".$_REQUEST;
> ?>
>
> and somebody enters, say "jkhdsjh" into the form, is_int() returns 1,
> thereby not setting the $_REQUEST variable to 10 - if I switch to
> using is_numeric then everything works as it should. Obviously, this isn't
> ideal as somebody could then enter 2.5 rather than the integers that I
> want to be passed.
>
> Looking at the source, this is in ext/standard/type.c in the php_is_type()
> function which seems to be messing up.
>
> Can anybody confirm this is:
> a) undesired behaviour and I'm not just being very "special" and
> b) that this is happening. I've tried on two boxes with 5.1.1 but it'd
> help to get somebody else's opinion
>
> If it's a bug, I'll do a patch up later tonight - just want to get it
> confirmed first.
>
> Cheers.
>
> --
> Gareth Ardron
>
> both debian/linux boxes. One i386, one x86_64.

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#2 Nov. 29, 2005 17:20:41

Gareth A.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Re: is_int/is_numeric possible bug


Ron Korving wrote:Just out of curiosity, to which versions does this apply?5.1.0b3->5.1.1 at least. Haven't got anything older to test on.

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#3 Nov. 29, 2005 17:37:23

Matteo B.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Re: is_int/is_numeric possible bug


Gareth Ardron wrote:Ron Korving wrote:Just out of curiosity, to which versions does this apply?5.1.0b3->5.1.1 at least. Haven't got anything older to test on.As far as I know request variables have always been strings, andis_int() checks the variable type, not its content.I wonder how your code was previously working ;)


For reference:http://www.php.net/is_intBest regards
--
Matteo Beccatihttp://phpadsnew.comhttp://phppgads.com--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#4 Nov. 29, 2005 17:41:23

Gareth A.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Re: is_int/is_numeric possible bug


Matteo Beccati wrote:Gareth Ardron wrote:Ron Korving wrote:Just out of curiosity, to which versions does this apply?5.1.0b3->5.1.1 at least. Haven't got anything older to test on.As far as I know request variables have always been strings, andis_int() checks the variable type, not its content.I wonder how your code was previously working ;)It wasn't, I was just helping a mate do something. New code.But still, it seems very odd to me - I mean, why does is_numeric()therefore work when is_int() doesn't - that seems like strange logic tome (though I admit I'm not the most logical of people).I just don't see the need to have to do:

if (is_numeric($_REQUEST) && is_int($_REQUEST)) {

when, at least in my mind, is_int() should do the job by itself.

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#5 Nov. 29, 2005 17:47:42

Ben L.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Re: is_int/is_numeric possible bug


is_numeric will test if it's a numeric string. Maybe is_int should do thesame, but apparently it doesn't.You could always do an is_numeric and if it returns true, cast it as anint.On Tue, 29 Nov 2005 12:42:10 -0500, Gareth Ardron <>wrote:Matteo Beccati wrote:Gareth Ardron wrote:Ron Korving wrote:Just out of curiosity, to which versions does this apply?5.1.0b3->5.1.1 at least. Haven't got anything older to test on.As far as I know request variables have always been strings, andis_int() checks the variable type, not its content.I wonder how your code was previously working ;)It wasn't, I was just helping a mate do something. New code.But still, it seems very odd to me - I mean, why does is_numeric()therefore work when is_int() doesn't - that seems like strange logic tome (though I admit I'm not the most logical of people).I just don't see the need to have to do:

if (is_numeric($_REQUEST) && is_int($_REQUEST)) {

when, at least in my mind, is_int() should do the job by itself.--
Using Opera's revolutionary e-mail client:http://www.opera.com/mail/--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#6 Nov. 29, 2005 17:51:26

Matteo B.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Re: is_int/is_numeric possible bug


Ben Litton wrote:is_numeric will test if it's a numeric string. Maybe is_int should dothe same, but apparently it doesn't.You could always do an is_numeric and if it returns true, cast it as anint.Or use: www.php.net/ctype_digit


Ciao ciao
--
Matteo Beccatihttp://phpadsnew.comhttp://phppgads.com--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#7 Nov. 29, 2005 17:52:03

Sara G.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Re: is_int/is_numeric possible bug


is_numeric will test if it's a numeric string. Maybe is_int should do thesame, but apparently it doesn't.What on earth for?If you want content, do is_numeric(). If you want type, do is_int()....Simple.-Sara

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#8 Nov. 29, 2005 17:52:52

Stefan E.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Re: is_int/is_numeric possible bug


Please move the discussion to php general mailinglist. This is a
usererror, a misunderstanding of is_int vs. is_numeric.

The documentation clearly states, that

is_numeric - Finds whether a variable is a number or a numeric string
is_int - Find whether a variable is an integer

anything within $_REQUEST is a string. Documentation clearly says that
is_int will return false, because a string is not an integer. is_numeric
will return true, because it is a numeric string.

Stefan

--
--------------------------------------------------------------------------
Stefan Esser
Hardened-PHP Projecthttp://www.hardened-php.net/GPG-Key gpg --keyserver pgp.mit.edu --recv-key 0x15ABDA78
Key fingerprint 7806 58C8 CFA8 CE4A 1C2C 57DD 4AE1 795E 15AB DA78
--------------------------------------------------------------------------

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#9 Nov. 29, 2005 17:57:11

Gareth A.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Re: is_int/is_numeric possible bug


Stefan Esser wrote:Please move the discussion to php general mailinglist. This is a
usererror, a misunderstanding of is_int vs. is_numeric.My bad therefore, misunderstanding of the docs as you say.Not sure I think it's entirely sane, but feh - it's been a long day,what do I know, etc etc.Cheers to those who replied.

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#10 Nov. 29, 2005 17:57:51

Ben L.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Re: is_int/is_numeric possible bug


On Tue, 29 Nov 2005 12:53:47 -0500, "Sara Golemon" <> wrote:is_numeric will test if it's a numeric string. Maybe is_int should dothe same, but apparently it doesn't.What on earth for?If you want content, do is_numeric(). If you want type, do is_int()....Simple.-SaraPHP lets you get away without worrying about types often enough thatpeople slip up on this. I don't know if most PHP users care if the valueof a variable is a "4" or a 4 but yes, it's easy enough to get around.--
Using Opera's revolutionary e-mail client:http://www.opera.com/mail/--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

  • Root
  • » PHP
  • » [PHP-DEV] Re: is_int/is_numeric possible bug [RSS Feed]

Board footer

Moderator control

Enjoy the 23rd of January
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support