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

Skip to content

Commit b5dc77e

Browse files
minor #40272 [Console] Handle calls to mb_ functions with non string arguments (Yopai)
This PR was merged into the 4.4 branch. Discussion ---------- [Console] Handle calls to mb_ functions with non string arguments | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #40200 | License | MIT | Doc PR | no In PHP8.1, a number of functions who were accepting null arguments will only accept string ones. (see https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg) In the polyfill, mb_* functions are already declared with a strict type checking of "string". Therefore, it is necessary to get rid of the use of non string arguments when calling mb_* functions, so that it won't break when either using the polyfill,or future php8 versions. In every call where the argument may not be a string, this commit enforces the string type of the argument (with transtyping) --- For reviewers * I generally don't like transtyping, but found it was the more "secure" way (on a non-BC point of view) here. Specially in Console/Helper/Table.php, where $cell can be an object (there are 2 "$cell instanceof ... tests) However, where the argument can already be either null or string (and not anything else), there may a beter approach ? * It's the first time I send a PR on symfony, so don't hesitate pointing me to thinks I've forgotten to done. Commits ------- ac45be2 In calls to mb_ functions, silently transform arg into string
2 parents 1688e5d + ac45be2 commit b5dc77e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
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
}

0 commit comments

Comments
 (0)