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

[5.3] Restore support for non-string needle in Str::startsWith() #15397

Merged
merged 3 commits into from
Sep 12, 2016
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
4 changes: 2 additions & 2 deletions src/Illuminate/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static function contains($haystack, $needles)
public static function endsWith($haystack, $needles)
{
foreach ((array) $needles as $needle) {
if ((string) $needle === substr($haystack, -strlen($needle))) {
if (substr($haystack, -strlen($needle)) === (string) $needle) {
return true;
}
}
Expand Down Expand Up @@ -403,7 +403,7 @@ public static function snake($value, $delimiter = '_')
public static function startsWith($haystack, $needles)
{
foreach ((array) $needles as $needle) {
if ($needle != '' && substr($haystack, 0, strlen($needle)) === $needle) {
if ($needle != '' && substr($haystack, 0, strlen($needle)) === (string) $needle) {
return true;
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/Support/SupportStrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function testStartsWith()
$this->assertFalse(Str::startsWith('jason', 'day'));
$this->assertFalse(Str::startsWith('jason', ['day']));
$this->assertFalse(Str::startsWith('jason', ''));
$this->assertFalse(Str::startsWith('7', ' 7'));
}

public function testEndsWith()
Expand Down