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

Appearance settings

Commit bc43d4e

Browse filesBrowse files
minor #41561 [String] Fix implicit float-to-int casts (derrabus)
This PR was merged into the 5.2 branch. Discussion ---------- [String] Fix implicit float-to-int casts | Q | A | ------------- | --- | Branch? | 5.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Part of #41552 | License | MIT | Doc PR | N/A `str_repeat()` expects an integer, but the result of the division might be a float. PHP 8.1 will complain here, so I'm using an integer division instead. Commits ------- 448a017 [String] Fix implicit float-to-int casts
2 parents 475ddaf + 448a017 commit bc43d4e
Copy full SHA for bc43d4e

File tree

1 file changed

+4
-4
lines changed
Filter options

1 file changed

+4
-4
lines changed

‎src/Symfony/Component/String/AbstractUnicodeString.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/String/AbstractUnicodeString.php
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,22 +480,22 @@ private function pad(int $len, self $pad, int $type): parent
480480

481481
switch ($type) {
482482
case \STR_PAD_RIGHT:
483-
return $this->append(str_repeat($pad->string, $freeLen / $padLen).($len ? $pad->slice(0, $len) : ''));
483+
return $this->append(str_repeat($pad->string, intdiv($freeLen, $padLen)).($len ? $pad->slice(0, $len) : ''));
484484

485485
case \STR_PAD_LEFT:
486-
return $this->prepend(str_repeat($pad->string, $freeLen / $padLen).($len ? $pad->slice(0, $len) : ''));
486+
return $this->prepend(str_repeat($pad->string, intdiv($freeLen, $padLen)).($len ? $pad->slice(0, $len) : ''));
487487

488488
case \STR_PAD_BOTH:
489489
$freeLen /= 2;
490490

491491
$rightLen = ceil($freeLen);
492492
$len = $rightLen % $padLen;
493-
$str = $this->append(str_repeat($pad->string, $rightLen / $padLen).($len ? $pad->slice(0, $len) : ''));
493+
$str = $this->append(str_repeat($pad->string, intdiv($rightLen, $padLen)).($len ? $pad->slice(0, $len) : ''));
494494

495495
$leftLen = floor($freeLen);
496496
$len = $leftLen % $padLen;
497497

498-
return $str->prepend(str_repeat($pad->string, $leftLen / $padLen).($len ? $pad->slice(0, $len) : ''));
498+
return $str->prepend(str_repeat($pad->string, intdiv($leftLen, $padLen)).($len ? $pad->slice(0, $len) : ''));
499499

500500
default:
501501
throw new InvalidArgumentException('Invalid padding type.');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.