Skip to content

Commit 0afa250

Browse files
committed
bug symfony#38080 [Console] Make sure $maxAttempts is an int or null (derrabus)
This PR was submitted for the 4.4 branch but it was merged into the 3.4 branch instead. Discussion ---------- [Console] Make sure $maxAttempts is an int or null | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | symfony#36872 | License | MIT | Doc PR | N/A The behavior of the "less than" operator for mixed types has changed in php 8. It is now possible to call `setMaxAttempts()` with a random string without raising the expected `InvalidArgumentException`. I've added an explicit type cast in order to restore the previous behavior. Commits ------- 4fcd491 [Console] Make sure $maxAttempts is an int or null.
2 parents ee8fc9c + 4fcd491 commit 0afa250

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/Symfony/Component/Console/Question/Question.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,11 @@ public function getValidator()
188188
*/
189189
public function setMaxAttempts($attempts)
190190
{
191-
if (null !== $attempts && $attempts < 1) {
192-
throw new InvalidArgumentException('Maximum number of attempts must be a positive value.');
191+
if (null !== $attempts) {
192+
$attempts = (int) $attempts;
193+
if ($attempts < 1) {
194+
throw new InvalidArgumentException('Maximum number of attempts must be a positive value.');
195+
}
193196
}
194197

195198
$this->attempts = $attempts;

0 commit comments

Comments
 (0)