Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issues with NAN #298

Open
Levivb opened this issue Feb 21, 2020 · 3 comments
Open

issues with NAN #298

Levivb opened this issue Feb 21, 2020 · 3 comments

Comments

@Levivb
Copy link

Levivb commented Feb 21, 2020

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?

@githoober
Copy link

This library seems abandoned.

@Levivb
Copy link
Author

Levivb commented May 21, 2020

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

@rquadling
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants