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

[9.x] Update PHP8 string function #38071

Merged
merged 1 commit into from
Jul 19, 2021
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
6 changes: 3 additions & 3 deletions src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,8 @@ protected function serializeClassCastableAttribute($key, $value)
*/
protected function isCustomDateTimeCast($cast)
{
return strncmp($cast, 'date:', 5) === 0 ||
strncmp($cast, 'datetime:', 9) === 0;
return str_starts_with($cast, 'date:') ||
str_starts_with($cast, 'datetime:');
}

/**
Expand All @@ -681,7 +681,7 @@ protected function isCustomDateTimeCast($cast)
*/
protected function isDecimalCast($cast)
{
return strncmp($cast, 'decimal:', 8) === 0;
return str_starts_with($cast, 'decimal:');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public static function camel($value)
public static function contains($haystack, $needles)
{
foreach ((array) $needles as $needle) {
if ($needle !== '' && mb_strpos($haystack, $needle) !== false) {
if ($needle !== '' && str_contains($haystack, $needle)) {
return true;
}
}
Expand Down Expand Up @@ -699,7 +699,7 @@ public static function snake($value, $delimiter = '_')
public static function startsWith($haystack, $needles)
{
foreach ((array) $needles as $needle) {
if ((string) $needle !== '' && strncmp($haystack, $needle, strlen($needle)) === 0) {
if ((string) $needle !== '' && str_starts_with($haystack, $needle)) {
return true;
}
}
Expand Down