diff --git a/src/helpers.php b/src/helpers.php index 21e3342..f2a8269 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -76,6 +76,9 @@ function array_except($array, $keys) /** * Return the first element in an array passing a given truth test. * + * @deprecated A native function with the same name was introduced in PHP 8.5. + * Use Illuminate\Support\Arr::first to keep functionality + * * @param array $array * @param callable|null $callback * @param mixed $default @@ -83,7 +86,21 @@ function array_except($array, $keys) */ function array_first($array, ?callable $callback = null, $default = null) { - return Arr::first($array, $callback, $default); + if (is_null($callback)) { + if (empty($array)) { + return value($default); + } + + foreach ($array as $item) { + return $item; + } + + return value($default); + } + + $key = array_find_key($array, $callback); + + return $key !== null ? $array[$key] : value($default); } } @@ -148,6 +165,9 @@ function array_has($array, $keys) /** * Return the last element in an array passing a given truth test. * + * @deprecated A native function with the same name was introduced in PHP 8.5. + * Use Illuminate\Support\Arr::last to keep functionality + * * @param array $array * @param callable|null $callback * @param mixed $default @@ -155,7 +175,11 @@ function array_has($array, $keys) */ function array_last($array, ?callable $callback = null, $default = null) { - return Arr::last($array, $callback, $default); + if (is_null($callback)) { + return empty($array) ? value($default) : end($array); + } + + return Arr::first(array_reverse($array, true), $callback, $default); } } @@ -403,13 +427,30 @@ function str_before($subject, $search) /** * Determine if a given string contains a given substring. * + * @deprecated A native function with the same name was introduced in PHP 8.0. + * Use Illuminate\Support\Str::contains to keep functionality + * * @param string $haystack * @param string|array $needles * @return bool */ function str_contains($haystack, $needles) { - return Str::contains($haystack, $needles); + if (is_null($haystack)) { + return false; + } + + if (! is_iterable($needles)) { + $needles = (array) $needles; + } + + foreach ($needles as $needle) { + if ($needle !== '' && strpos($haystack, $needle) !== false) { + return true; + } + } + + return false; } }