assert icon indicating copy to clipboard operation
assert copied to clipboard

issues with NAN

Open Levivb opened this issue 6 years ago • 3 comments

Hey,

Thanks for this handy package.

PHP has some weird constructs regarding NAN Note this repl output:

>>> Assert::that(NAN)->integer() // expected behaviour
Assert/InvalidArgumentException with message 'Value "NAN" is not an integer.'
>>> Assert::that(NAN)->between(1,3) // expected InvalidArgumentException. Returns chain
=> Assert\AssertionChain {#4203}
>>> NAN > 0
=> false
>>> NAN > -999
=> false
>>> NAN < 999
=> false
>>> NAN < -999
=> false
>>> is_float(NAN)
=> true
>>> is_numeric(NAN)
=> true
>>> is_integer(NAN)
=> false
>>> is_integer(INF)
=> false
>>> is_float(INF)
=> true

We're dealing with code like this:

public function __construct(float $longitude, float $latitude, string $city)
{
        Assert::that($longitude)->between(-180, 180);

Even php itself issues no Exception when passing NAN into this constructor with float typehint. Would it be feasible to add a isNotNan check and/or update existing assertions to take this (inconsistency?) into account?

Levivb avatar Feb 21 '20 10:02 Levivb

This library seems abandoned.

githoober avatar May 21 '20 06:05 githoober

probably. we're going to step over to https://github.com/webmozart/assert anyway

Levivb avatar May 21 '20 08:05 Levivb

It's not abandoned ... just not got much time at the moment.

rquadling avatar May 22 '20 11:05 rquadling