#41105 [Bgs]: FILTER_FLAG_ALLOW_{HEX,OCTAL} do nothing
| From: | dohpaz at gmail dot com | Date: | Mon, 16 Apr 2007 16:18:57 +0000 |
| Subject: | #41105 [Bgs]: FILTER_FLAG_ALLOW_{HEX,OCTAL} do nothing | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-111552@lists.php.net to get a copy of this message | ||
ID: 41105
User updated by: dohpaz at gmail dot com
Reported By: dohpaz at gmail dot com
Status: Bogus
Bug Type: Filter related
Operating System: Linux 2.6.18.1
PHP Version: 5.2.1
New Comment:
Ok, that makes more sense. However, if I try to do an identical
comparison (===) between what filter_var() returns and my original
value, I get false.
<?php
var_dump(filter_var("0x42", FILTER_VALIDATE_INT,
FILTER_FLAG_ALLOW_HEX) === "0x42");
?>
Since most other validations return the original content as a success,
I would expect the same in this case also. Advise if I should open a new
ticket for this scenario or not.
Previous Comments:
------------------------------------------------------------------------
[2007-04-16 16:06:24] tony2001@php.net
0x42 is already parsed by PHP itself and it's apparently equal to 66.
"0x42" is what you need to use.
------------------------------------------------------------------------
[2007-04-16 15:53:08] dohpaz at gmail dot com
Description:
------------
The problem I am facing is that filter_var(), coupled with
FILTER_FLAG_ALLOW_{HEX,OCTAL} flags, is not working as I would expect. I
would expect that using either of those flags would only allow their
respective notations. Instead, they pretty much do nothing. I can call
filter_var() using the FILTER_VALIDATE_INT, and any combination of
filter flags, and get the same exact results each time. This is
deomonstrated below:
1. filter_var(42, FILTER_VALIDATE_INT): int(42) (Expected integer value
42)
2. filter_var(42, FILTER_VALIDATE_INT, FILTER_FLAG_ALLOW_HEX): int(42)
(Expected boolean value FALSE)
3. filter_var(0x42, FILTER_VALIDATE_INT, FILTER_FLAG_ALLOW_HEX):
int(66) (Expected integer value 66)
4. filter_var(0x42, FILTER_VALIDATE_INT, FILTER_FLAG_ALLOW_OCTAL):
int(66) (Expected boolean value FALSE)
So I guess my question is, what is the point of having these seperate
flags that seemingly do nothing? Maybe this is a lack of _GOOD_
documentation in the PHP manual, but I would expect to be able to use
filter_var() to distinguish between numbers using different bases.
Afterall, 42 is not the same as 0x42, or 042.
Finally, why is filter_var() just limited to three base systems?
Wouldn't it make much more sense for there to be an option, perhaps
called 'base', that would allow any arbitrary base (2, 13, 8, 16, etc)
and validate the input on that?
Reproduce code:
---------------
1. <?php var_dump(filter_var(42, FILTER_VALIDATE_INT)); ?>
2. <?php var_dump(filter_var(42, FILTER_VALIDATE_INT,
FILTER_FLAG_ALLOW_HEX)); ?>
3. <?php var_dump(filter_var(0x42, FILTER_VALIDATE_INT,
FILTER_FLAG_ALLOW_HEX)); ?>
4. <?php var_dump(filter_var(0x42, FILTER_VALIDATE_INT,
FILTER_FLAG_ALLOW_OCTAL)); ?>
Expected result:
----------------
1. 42 (as expected)
2. FALSE (got 42 instead)
3. 66 (as expected)
4. FALSE (got 66 instead)
Actual result:
--------------
1. 42
2. 42
3. 66
4. 66
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=41105&edit=1