Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4670282

Browse files
committed
In calls to mb_ functions, silently transform arg into string
In PHP8, a number of functions who were accepting null arguments will only accept string ones. In the polyfill, mb_* functions are declared with a trict type checking of "string". Therefore, we deprecate the use of non string arguments, so that it won't break when either using the polyfill, or future php8 versions.
1 parent 4ee48c4 commit 4670282

File tree

8 files changed

+17
-6
lines changed

8 files changed

+17
-6
lines changed

src/Symfony/Component/Console/Helper/Helper.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public function getHelperSet()
4747
*/
4848
public static function strlen($string)
4949
{
50+
$string = (string) $string;
51+
5052
if (false === $encoding = mb_detect_encoding($string, null, true)) {
5153
return \strlen($string);
5254
}
@@ -65,6 +67,8 @@ public static function strlen($string)
6567
*/
6668
public static function substr($string, $from, $length = null)
6769
{
70+
$string = (string) $string;
71+
6872
if (false === $encoding = mb_detect_encoding($string, null, true)) {
6973
return substr($string, $from, $length);
7074
}

src/Symfony/Component/Console/Helper/Table.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,9 @@ private function renderCell(array $row, int $column, string $cellFormat): string
513513
}
514514

515515
// str_pad won't work properly with multi-byte strings, we need to fix the padding
516-
if (false !== $encoding = mb_detect_encoding($cell, null, true)) {
517-
$width += \strlen($cell) - mb_strwidth($cell, $encoding);
516+
$cellstr = (string) $cell;
517+
if (false !== $encoding = mb_detect_encoding($cellstr, null, true)) {
518+
$width += \strlen($cellstr) - mb_strwidth($cellstr, $encoding);
518519
}
519520

520521
$style = $this->getColumnStyle($column);
@@ -523,7 +524,7 @@ private function renderCell(array $row, int $column, string $cellFormat): string
523524
return sprintf($style->getBorderFormat(), str_repeat($style->getBorderChars()[2], $width));
524525
}
525526

526-
$width += Helper::strlen($cell) - Helper::strlenWithoutDecoration($this->output->getFormatter(), $cell);
527+
$width += Helper::strlen($cellstr) - Helper::strlenWithoutDecoration($this->output->getFormatter(), $cellstr);
527528
$content = sprintf($style->getCellRowContentFormat(), $cell);
528529

529530
return sprintf($cellFormat, str_pad($content, $width, $style->getPaddingChar(), $style->getPadType()));

src/Symfony/Component/ErrorHandler/Resources/views/exception.html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
<div class="exception-message-wrapper">
1818
<div class="container">
19-
<h1 class="break-long-words exception-message<?= mb_strlen($exceptionMessage) > 180 ? ' long' : ''; ?>"><?= $this->formatFileFromText(nl2br($exceptionMessage)); ?></h1>
19+
<h1 class="break-long-words exception-message<?= mb_strlen((string) $exceptionMessage) > 180 ? ' long' : ''; ?>"><?= $this->formatFileFromText(nl2br($exceptionMessage)); ?></h1>
2020

2121
<div class="exception-illustration hidden-xs-down">
2222
<?= $this->include('assets/images/symfony-ghost.svg.php'); ?>

src/Symfony/Component/HttpFoundation/BinaryFileResponse.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ public function setAutoEtag()
155155
*/
156156
public function setContentDisposition($disposition, $filename = '', $filenameFallback = '')
157157
{
158+
$filename = (string) $filename;
159+
158160
if ('' === $filename) {
159161
$filename = $this->file->getFilename();
160162
}

src/Symfony/Component/Mime/Test/Constraint/EmailHtmlBodyContains.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected function matches($message): bool
4343
throw new \LogicException('Unable to test a message HTML body on a RawMessage or Message instance.');
4444
}
4545

46-
return false !== mb_strpos($message->getHtmlBody(), $this->expectedText);
46+
return false !== mb_strpos((string) $message->getHtmlBody(), $this->expectedText);
4747
}
4848

4949
/**

src/Symfony/Component/Mime/Test/Constraint/EmailTextBodyContains.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected function matches($message): bool
4343
throw new \LogicException('Unable to test a message text body on a RawMessage or Message instance.');
4444
}
4545

46-
return false !== mb_strpos($message->getTextBody(), $this->expectedText);
46+
return false !== mb_strpos((string) $message->getTextBody(), $this->expectedText);
4747
}
4848

4949
/**

src/Symfony/Component/Translation/Dumper/IcuResFileDumper.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public function formatCatalogue(MessageCatalogue $messages, $domain, array $opti
4242
$keyTop = $this->getPosition($data);
4343

4444
foreach ($messages->all($domain) as $source => $target) {
45+
$target = (string) $target;
46+
4547
$resources .= pack('V', $this->getPosition($data));
4648

4749
$data .= pack('V', \strlen($target))

src/Symfony/Component/VarDumper/Dumper/CliDumper.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ public function dumpScalar(Cursor $cursor, $type, $value)
185185
*/
186186
public function dumpString(Cursor $cursor, $str, $bin, $cut)
187187
{
188+
$str = (string) $str;
189+
188190
$this->dumpKey($cursor);
189191
$attr = $cursor->attr;
190192

0 commit comments

Comments
 (0)