-
Notifications
You must be signed in to change notification settings - Fork 545
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
Add support for FILTER_NULL_ON_FAILURE flag in filter_var #73
Conversation
bc4027b to
12f1892
Compare
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
12f1892 to
e83948c
Compare
Hi, build is failing, but I like the code, will merge once the build passes :)
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.
00d334e to
bc1a93c
Compare
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.
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?
@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.
f3ccc98 to
b2955d2
Compare
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.
Great, thank you!
Uh oh!
There was an error while loading. Please reload this page.
This adds support for the
FILTER_NULL_ON_FAILUREflag.This doesn't cover all possible edge cases of the
filter_varfunction, namely:Fixes phpstan/phpstan#1959