diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md
index dd4ff449450..1935d097811 100644
--- a/framework/CHANGELOG.md
+++ b/framework/CHANGELOG.md
@@ -10,7 +10,6 @@ Yii Framework 2 Change Log
- Bug #20256: Add support for dropping views in MSSQL server when running migrate/fresh (ambrozt)
- Enh #20248: Add support for attaching behaviors in configurations with Closure (timkelty)
- Enh #20268: Minor optimisation in `\yii\helpers\BaseArrayHelper::map` (chriscpty)
-- Enh #20268: Add `\yii\helpers\BaseStringHelper::contains()` as a polyfill for `str_contains` (chriscpty)
2.0.51 July 18, 2024
--------------------
diff --git a/framework/helpers/BaseArrayHelper.php b/framework/helpers/BaseArrayHelper.php
index 334f55112e0..bc770f96cb7 100644
--- a/framework/helpers/BaseArrayHelper.php
+++ b/framework/helpers/BaseArrayHelper.php
@@ -595,7 +595,7 @@ public static function getColumn($array, $name, $keepKeys = true)
*/
public static function map($array, $from, $to, $group = null)
{
- if (is_string($from) && is_string($to) && $group === null && !\yii\helpers\StringHelper::contains($from, '.') && !\yii\helpers\StringHelper::contains($to, '.')) {
+ if (is_string($from) && is_string($to) && $group === null && strpos($from, '.') === false && strpos($to, '.') === false) {
return array_column($array, $to, $from);
}
$result = [];
diff --git a/framework/helpers/BaseStringHelper.php b/framework/helpers/BaseStringHelper.php
index bcecca8485b..5854e29766d 100644
--- a/framework/helpers/BaseStringHelper.php
+++ b/framework/helpers/BaseStringHelper.php
@@ -226,30 +226,6 @@ protected static function truncateHtml($string, $count, $suffix, $encoding = fal
return $generator->generateFromTokens($truncated) . ($totalCount >= $count ? $suffix : '');
}
- /**
- * @param string $string The input string.
- * @param string $needle Part to search inside $string
- * @param bool $caseSensitive Case sensitive search. Default is true. When case sensitive is enabled, `$with` must
- * exactly match the starting of the string in order to get a true value.
- * @return bool
- */
- public static function contains($string, $needle, $caseSensitive = true)
- {
- $string = (string)$string;
- $needle = (string)$needle;
-
- if ($caseSensitive) {
- // can be replaced with just the str_contains call when minimum supported PHP version is raised to 8.0 or higher
- if (function_exists('str_contains')) {
- return str_contains($string, $needle);
- }
- $encoding = Yii::$app ? Yii::$app->charset : 'UTF-8';
- return mb_strpos($string, $needle, 0, $encoding) !== false;
- }
- $encoding = Yii::$app ? Yii::$app->charset : 'UTF-8';
- return mb_stripos($string, $needle, 0, $encoding) !== false;
- }
-
/**
* Check if given string starts with specified substring. Binary and multibyte safe.
*
diff --git a/tests/framework/helpers/StringHelperTest.php b/tests/framework/helpers/StringHelperTest.php
index 49ffee0d876..5f222ec4e7a 100644
--- a/tests/framework/helpers/StringHelperTest.php
+++ b/tests/framework/helpers/StringHelperTest.php
@@ -150,15 +150,6 @@ public function testTruncateWords()
$this->assertEquals('This is a test for...', StringHelper::truncateWords('This is a test for a sentance', 5, '...', true));
}
- public function testContains()
- {
- $this->assertEquals(true, StringHelper::contains('Test', 'st'));
- $this->assertEquals(false, StringHelper::contains('Test', 'ts'));
- $this->assertEquals(false, StringHelper::contains('Test', 'St'));
- $this->assertEquals(true, StringHelper::contains('Test', 'St', false));
- $this->assertEquals(false, StringHelper::contains('Test', 'Ste', false));
- }
-
/**
* @dataProvider providerStartsWith
* @param bool $result