On Mon, 04 Feb 2013 12:14:50 +0100, Frank Liepert <frank.liep...@gmx.de>
wrote:
The change to FILTER_VALIDATE_INT seems to be inconsistent.
First of all, take the following bug
(https://bugs.php.net/bug.php?id=54096) where it says "PHP defines -0 as
an int.". Where does PHP define it? The documentation says: "An integer
is a number of the set ℤ = {..., -2, -1, 0, 1, 2, ...}."
Secondly, try the following code: var_dump(round(-0.1));
What is the result? Surprise: float(-0)
And it is not a bug (https://bugs.php.net/bug.php?id=42477)
To sum it up:
- FILTER_VALIDATE_INT should never treat "+0" or "-0" as valid integers.
- Instead, var_dump needs to be corrected.
- It could be even gone further in adding support for signed zero
arithmetic (see IEEE754).
You're confusing things. Floats are irrelevant to this discussion. It's
clear -0. (float) does exist and has a well defined meaning. The situation
is manifestly different for integers because there are no separate
positive and negative 0 integers in most likely all the architectures PHP
runs on.
So the question is only whether "+0" or "-0" (or "+0", etc.) should be
accepted as integers by FILTER_VALIDATE_INT. I think they should, because
we also accept non-canonical inputs such as "+5", i.e., we always accept a
sign. It's true that 0 is neither positive or negative, but I don't think
"accepts a leading sign, except if it's 0" is a good option. It's an
unnecessary special case.
Finally, please don't top post. See
http://lxr.php.net/xref/PHP_TRUNK/README.MAILINGLIST_RULES#67
--
Gustavo Lopes
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php