-
Notifications
You must be signed in to change notification settings - Fork 537
Fix filter var on uncertainty flags #4418
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
base: 2.1.x
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -7354,8 +7354,8 @@ public static function dataFilterVar(): Generator | |
|
||
$typeAndFlags = [ | ||
['%s|false', ''], | ||
['%s|false', ', $mixed'], | ||
['%s|false', ', ["flags" => $mixed]'], | ||
['mixed', ', $mixed'], | ||
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. This was wrong, with a mixed flag it's not necessary |
||
['mixed', ', ["flags" => $mixed]'], | ||
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. This was wrong, with a mixed flag it's not necessary |
||
['%s|null', ', FILTER_NULL_ON_FAILURE'], | ||
['%s|null', ', ["flags" => FILTER_NULL_ON_FAILURE]'], | ||
['%s|null', ', ["flags" => FILTER_NULL_ON_FAILURE | FILTER_FLAG_IPV4]'], | ||
|
@@ -7384,8 +7384,8 @@ public static function dataFilterVar(): Generator | |
|
||
$boolFlags = [ | ||
['bool', ''], | ||
['bool', ', $mixed'], | ||
['bool', ', ["flags" => $mixed]'], | ||
['mixed', ', $mixed'], | ||
['mixed', ', ["flags" => $mixed]'], | ||
Comment on lines
+7387
to
+7388
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. This was wrong, with a mixed flag it's not necessary |
||
['bool|null', ', FILTER_NULL_ON_FAILURE'], | ||
['bool|null', ', ["flags" => FILTER_NULL_ON_FAILURE]'], | ||
['bool|null', ', ["flags" => FILTER_NULL_ON_FAILURE | FILTER_FLAG_IPV4]'], | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,7 +90,7 @@ public function invalidInput(array $arr, object $object, $resource): void | |
public function intToInt(int $int, array $options): void | ||
{ | ||
assertType('int', filter_var($int, FILTER_VALIDATE_INT)); | ||
assertType('int|false', filter_var($int, FILTER_VALIDATE_INT, $options)); | ||
assertType('mixed', filter_var($int, FILTER_VALIDATE_INT, $options)); | ||
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. This was wrong, with a array $options, the flag might be mixed. And with a mixed flag it's not necessary |
||
assertType('int<0, max>|false', filter_var($int, FILTER_VALIDATE_INT, ['options' => ['min_range' => 0]])); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Bug11485; | ||
|
||
class Foo { | ||
|
||
public function bar(string $value, bool $strict = true): bool { | ||
|
||
$flags = $strict ? FILTER_NULL_ON_FAILURE : 0; | ||
$result = filter_var($value, FILTER_VALIDATE_BOOLEAN, $flags); | ||
if ($result === null) throw new \Exception("not a boolean"); | ||
|
||
$result = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); | ||
if ($result === null) throw new \Exception("not a boolean"); | ||
|
||
return $result; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In next PR I'll add support for union of ConstantIntegerType