Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add support for FILTER_NULL_ON_FAILURE flag in filter_var #73

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

Merged
ondrejmirtes merged 3 commits into phpstan:master from BackEndTea:fix/filter_var_nullable
Jan 2, 2020

Conversation

@BackEndTea
Copy link
Contributor

@BackEndTea BackEndTea commented Jan 1, 2020
edited
Loading

This adds support for the FILTER_NULL_ON_FAILURE flag.

This doesn't cover all possible edge cases of the filter_var function, namely:

  • Default values

Fixes phpstan/phpstan#1959

This works for all validates, but not sanitizes.
For now this lacks support for bit masks, e.g.:
`FILTER_FLAG_IPV4 | FILTER_NULL_ON_FAILURE`. The reason for this is
that there is also a `FILTER_FORCE_ARRAY` flag, which puts the
result in an array. This option, or bit masks, aren't supported either
right now. So adding support for bitmasks without `FILTER_FORCE_ARRAY`
would result in more false positives
Copy link
Member

Hi, build is failing, but I like the code, will merge once the build passes :)

BackEndTea reacted with hooray emoji

This includes support for bit masks, and force array.
It also updates the old implementation of retrieving the constant, to
use the type system as well, allow usage of variables.
Copy link
Contributor Author

Small thing to note:

This does not support default values yet, as that has some weird behavior in combination with array inputs: https://3v4l.org/NbAhc. This wasn't supported before, so it shouldn't introduce any new errors.

Copy link
Contributor Author

This does introduce a dependency on ext-filter: https://travis-ci.org/phpstan/phpstan-src/jobs/631844108#L402 Which can be disabled according to the documentation.

Should we introduce an explicit dependency in composer.json?

Copy link
Member

@BackEndTea No, the code should check whether the constant exists first.

All of the constants got added way before php 7.1, so there is no
need to check for each of them individually.
Copy link
Contributor Author

I've added the check, but only for 1 constant, as that should mean the rest of them are available as well, since all of them got introduced somewhere around PHP 5.2. So checking every single one individually doesn't add much benefit.

Copy link
Member

Great, thank you!

@ondrejmirtes ondrejmirtes merged commit e15cfcd into phpstan:master Jan 2, 2020
@BackEndTea BackEndTea deleted the fix/filter_var_nullable branch January 2, 2020 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ondrejmirtes ondrejmirtes ondrejmirtes requested changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

filter_var extension should support FILTER_NULL_ON_FAILURE

AltStyle によって変換されたページ (->オリジナル) /