#47752 [Tbd]: FILTER_VALIDATE_INT doesn't allow "+0" and "-0"

From: Date: Tue, 24 Mar 2009 16:20:07 +0000
Subject: #47752 [Tbd]: FILTER_VALIDATE_INT doesn't allow "+0" and "-0"
References: 1  Groups: php.bugs php.doc.bugs 
Request: Send a blank email to doc-bugs+get-2038@lists.php.net to get a copy of this message
 ID:               47752
 Updated by:       scottmac@php.net
 Reported By:      for-bugs at hnw dot jp
 Status:           To be documented
 Bug Type:         Filter related
 Operating System: *
 PHP Version:      5.2.9
 New Comment:

The documentation should probably mention that +0 and -0 are valid
floats.

var_dump(filter_var("+0", FILTER_VALIDATE_FLOAT));
var_dump(filter_var("-0", FILTER_VALIDATE_FLOAT));



Previous Comments:
------------------------------------------------------------------------

[2009-03-24 15:22:37] pajoye@php.net

Make it a documentation bug instead, it should be documented and will
be, will add some other things while being at it :)

------------------------------------------------------------------------

[2009-03-24 15:15:17] pajoye@php.net

We have double checked again the design choices about -/+ 0, it was on
purpose. -0 or +0 are not valid integers.

Sorry, but we have to reject this request.

thanks for your understanding,

------------------------------------------------------------------------

[2009-03-24 15:03:53] peter at lvp-media dot com

Hereby a simple bug47752.phpt file. Tested it on a patched- an an
unpatched installation, results as expected. Strictly speaking +0 and -0
are valid integers, even though neither of them is positive or
negative.

Peter Beverloo

--TEST--
Bug #47752 (FILTER_VALIDATE_INT doesn't allow "+0" and "-0")
--FILE--
<?php
$positive = filter_var ('+0', FILTER_VALIDATE_INT);
$negative = filter_var ('-0', FILTER_VALIDATE_INT);
$zero     = filter_var ('0',  FILTER_VALIDATE_INT);
$octal    = filter_var ('-0123', FILTER_VALIDATE_INT);

var_dump ($positive);
var_dump ($negative);
var_dump ($zero);
var_dump ($octal);

?>
--EXPECT--
int(0)
int(0)
int(0)
bool(false)

------------------------------------------------------------------------

[2009-03-24 12:44:19] pajoye@php.net

As far as I remember it is on purpose. 0 cannot be negative or
positive.

But if we agree on allowing them again, no problem here.

Can you please provide tests as well (phpt)?

------------------------------------------------------------------------

[2009-03-24 11:50:38] php at lvp-media dot com

False, this only allows +0 and -0 by checking the lenght of the string,
it verifies that the null is the only character in it.

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/47752

-- 
Edit this bug report at http://bugs.php.net/?id=47752&edit=1



Thread (3 messages)

« previous php.doc.bugs (#2038) next »