Skip to content
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

Deprecated: mb_strlen(): Passing null to parameter #1 ($string) of type string is deprecated #19833

Merged
merged 3 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Yii Framework 2 Change Log
- Bug #19813: Fix `yii\base\DynamicModel` validation with validators that reference missing attributes (michaelarnauts)
- Enh #19816: Explicitly pass `$fallbackToMaster` as `true` to `getSlavePdo()` to ensure it is not affected by child class with changed defaults (developedsoftware)
- Bug #19720: Fix "zh-HK" locale causing [error][yii\i18n\PhpMessageSource::loadFallbackMessages] The message file for category 'yii' does not exist (uaoleg)
- Bug #19736: Fix `StringHelper::truncate(null, 10)` causes error Deprecated: mb_strlen(): Passing null to parameter #1 ($string) of type string is deprecated (uaoleg)


2.0.47 November 18, 2022
------------------------
Expand Down
14 changes: 12 additions & 2 deletions framework/helpers/BaseStringHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static function byteSubstr($string, $start, $length = null)
$length = static::byteLength($string);
}

return mb_substr($string, $start, $length, '8bit');
return mb_substr((string)$string, $start, $length, '8bit');
}

/**
Expand All @@ -67,6 +67,8 @@ public static function byteSubstr($string, $start, $length = null)
*/
public static function basename($path, $suffix = '')
{
$path = (string)$path;

$len = mb_strlen($suffix);
if ($len > 0 && mb_substr($path, -$len) === $suffix) {
$path = mb_substr($path, 0, -$len);
Expand All @@ -93,7 +95,7 @@ public static function basename($path, $suffix = '')
public static function dirname($path)
{
$normalizedPath = rtrim(
str_replace('\\', '/', $path),
str_replace('\\', '/', (string)$path),
'/'
);
$separatorPosition = mb_strrpos($normalizedPath, '/');
Expand Down Expand Up @@ -122,6 +124,8 @@ public static function dirname($path)
*/
public static function truncate($string, $length, $suffix = '...', $encoding = null, $asHtml = false)
{
$string = (string)$string;

if ($encoding === null) {
$encoding = Yii::$app ? Yii::$app->charset : 'UTF-8';
}
Expand Down Expand Up @@ -233,6 +237,9 @@ protected static function truncateHtml($string, $count, $suffix, $encoding = fal
*/
public static function startsWith($string, $with, $caseSensitive = true)
{
$string = (string)$string;
$with = (string)$with;

if (!$bytes = static::byteLength($with)) {
return true;
}
Expand All @@ -257,6 +264,9 @@ public static function startsWith($string, $with, $caseSensitive = true)
*/
public static function endsWith($string, $with, $caseSensitive = true)
{
$string = (string)$string;
$with = (string)$with;

if (!$bytes = static::byteLength($with)) {
return true;
}
Expand Down