-
Notifications
You must be signed in to change notification settings - Fork 574
Fix phpstan/phpstan#14397: FILTER_FLAG_GLOBAL_RANGE constant not "known" on PHP 8.3, 8.4 #5334
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
Changes from 6 commits
fa75094
94b3785
67dec56
0608ee0
5d6f582
b46cca1
001b55d
b4f3ef5
d657e3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <?php // lint >= 8.2 | ||
|
|
||
| declare(strict_types = 1); | ||
|
|
||
| namespace Bug14397; | ||
|
|
||
| use PHPStan\TrinaryLogic; | ||
|
|
||
| use function filter_var; | ||
| use function PHPStan\Testing\assertType; | ||
| use function PHPStan\Testing\assertVariableCertainty; | ||
|
|
||
| function test(string $ipAddress): void | ||
| { | ||
| assertType('non-falsy-string|false', filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_GLOBAL_RANGE)); | ||
| } | ||
|
|
||
| function test2(mixed $mixed): void | ||
| { | ||
| try { | ||
| filter_var($mixed, FILTER_VALIDATE_INT, FILTER_FLAG_GLOBAL_RANGE); | ||
| $foo = 1; | ||
| } catch (\Filter\FilterFailedException $e) { | ||
| assertVariableCertainty(TrinaryLogic::createYes(), $foo); | ||
| } | ||
|
|
||
| assertType('int|false', filter_var($mixed, FILTER_VALIDATE_INT, FILTER_FLAG_GLOBAL_RANGE)); | ||
| assertType('int|false', filter_var($mixed, FILTER_VALIDATE_INT, ['flags' => FILTER_FLAG_GLOBAL_RANGE])); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <?php // lint < 8.5 | ||
|
|
||
| namespace FilterVarNullAndThrowPrePhp85; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we test this file on 8.5+ and pre-8.5?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Added a test ( |
||
|
|
||
| filter_var('foo@bar.test', FILTER_VALIDATE_EMAIL, FILTER_FLAG_GLOBAL_RANGE|FILTER_NULL_ON_FAILURE); | ||
|
|
||
| $flag = FILTER_NULL_ON_FAILURE|FILTER_FLAG_GLOBAL_RANGE; | ||
| filter_var(100, FILTER_VALIDATE_INT, $flag); | ||
|
|
||
| filter_var( | ||
| 'johndoe', | ||
| FILTER_VALIDATE_REGEXP, | ||
| ['options' => ['regexp' => '/^[a-z]+$/'], 'flags' => FILTER_FLAG_GLOBAL_RANGE|FILTER_NULL_ON_FAILURE] | ||
| ); | ||
Uh oh!
There was an error while loading. Please reload this page.