Electronics & Programming

develissimo

Open Source electronics development and programming

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

#1 Nov. 29, 2005 15:57:51

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

[PHP-DEV] is_int/is_numeric possible bug


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 switchto using is_numeric then everything works as it should. Obviously, thisisn't ideal as somebody could then enter 2.5 rather than the integersthat I want to be passed.Looking at the source, this is in ext/standard/type.c in thephp_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" andb) that this is happening. I've tried on two boxes with 5.1.1 butit'd help to get somebody else's opinionIf it's a bug, I'll do a patch up later tonight - just want to get itconfirmed 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 16:38:01

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

[PHP-DEV] is_int/is_numeric possible bug


Gareth Ardron wrote:
> Hi.
>
> Think I've just stumbled upon a possible bug with is_int.
Hello Gareth,
if I'm not mistaken, $_REQUEST is a string, and unless you use

if (!is_int(intval($_REQUEST)) || $_REQUEST < 0) {

I see no problem in is_int taking a string with numerals inside as not int.

Greetings,
Florian

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

Offline

#3 Nov. 29, 2005 16:44:25

Antony D.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] is_int/is_numeric possible bug


./sapi/cli/php -r 'var_dump(is_int("jkhdsjh"));'
bool(false)

./sapi/cli/php -v
PHP 5.1.2-dev (cli)

What am I doing wrong?

On 29.11.2005 18:57, Gareth Ardron wrote: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 switchto using is_numeric then everything works as it should. Obviously, thisisn't ideal as somebody could then enter 2.5 rather than the integersthat I want to be passed.Looking at the source, this is in ext/standard/type.c in thephp_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" andb) that this is happening. I've tried on two boxes with 5.1.1 butit'd help to get somebody else's opinionIf it's a bug, I'll do a patch up later tonight - just want to get itconfirmed first.Cheers.--Wbr,Antony Dovgal--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#4 Nov. 29, 2005 17:19:48

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

[PHP-DEV] is_int/is_numeric possible bug


Florian Anderiasch wrote:Gareth Ardron wrote:Hi.

Think I've just stumbled upon a possible bug with is_int.Hello Gareth,
if I'm not mistaken, $_REQUEST is a string, and unless you use

if (!is_int(intval($_REQUEST)) || $_REQUEST < 0) {

I see no problem in is_int taking a string with numerals inside as not int.the problem with this (which I did try before posting) is that of courseis somebody enters a text string, and you run intval() on that, it'llreturn 1, not 0 as it has content. Only if it's empty would it returnzero, and as such is_int() will return 1/true again.--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#5 Nov. 29, 2005 17:27:20

Antony D.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] is_int/is_numeric possible bug


On 29.11.2005 20:22, Gareth Ardron wrote:Antony Dovgal wrote:./sapi/cli/php -r 'var_dump(is_int("jkhdsjh"));'
bool(false)

./sapi/cli/php -v
PHP 5.1.2-dev (cli)

What am I doing wrong?well that's interesting.I think it's something to do with the way the var is passed - so couldeven be a problem with the apache sapi.I can hardly believe in that because the engine doesn't depend on the SAPI used.
Execute this code and see what you get.(I was using apache 1.3.33(stock debian release) just so you know.)And PHP from .deb too?
*That* could be a problem.

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

Offline

#6 Nov. 29, 2005 17:36:35

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

[PHP-DEV] is_int/is_numeric possible bug


Antony Dovgal wrote:And PHP from .deb too?
*That* could be a problem.God no, If I was doing that, I wouldn't report the bug here :)

Can give you the configure line if it'll help?

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

Offline

#7 Nov. 29, 2005 18:34:15

Unknown W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] is_int/is_numeric possible bug


If you're having that problem that a request variable is being reportedas an integer, I suggest using var_dump(). That function will tell youthe type and contents of a variable. For example:$bool = true;
$int = 1;
$float = 1.0;
$str = 'abc';
$array = array();

var_dump($bool, $int, $float, $str, $array);

Will give you:

bool(true)
int(1)
float(1)
string(3) "abc"
array(0) {
}All of the above are very different. A request variable should alwaysbe of type string, and if one is not then I suspect that may indeed be abug.Remember that PHP doesn't hide the type from you, it just simplifiesconversions and usage for you.In any case, if you want it to be 10 if it wasn't set to a valid int, Ithink you want:$_REQUEST = is_numeric($_REQUEST) ? (int)$_REQUEST : 10;Or similar. Note that this will treat "5.1" as 5, not as 10 (which maybe what you want.)-


-------- Original Message --------Antony Dovgal wrote:And PHP from .deb too?
*That* could be a problem.God no, If I was doing that, I wouldn't report the bug here :)

Can give you the configure line if it'll help?--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

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

Board footer

Moderator control

Enjoy the 24th of April
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