Skip to content

Commit 620fdda

Browse files
committed
strict types for replaceFirst
1 parent 28e97da commit 620fdda

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/Illuminate/Support/Str.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,8 @@ public static function replaceArray($search, array $replace, $subject)
501501
*/
502502
public static function replaceFirst($search, $replace, $subject)
503503
{
504-
if ($search == '') {
504+
$search = (string)$search;
505+
if ($search === '') {
505506
return $subject;
506507
}
507508

tests/Support/SupportStrTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ public function testReplaceFirst()
348348
$this->assertSame('foo foobar', Str::replaceFirst('bar', '', 'foobar foobar'));
349349
$this->assertSame('foobar foobar', Str::replaceFirst('xxx', 'yyy', 'foobar foobar'));
350350
$this->assertSame('foobar foobar', Str::replaceFirst('', 'yyy', 'foobar foobar'));
351+
$this->assertSame('1', Str::replaceFirst(0, '1', '0'));
351352
// Test for multibyte string support
352353
$this->assertSame('Jxxxnköping Malmö', Str::replaceFirst('ö', 'xxx', 'Jönköping Malmö'));
353354
$this->assertSame('Jönköping Malmö', Str::replaceFirst('', 'yyy', 'Jönköping Malmö'));

0 commit comments

Comments
 (0)